Sha256: d5857ff438f86844631586f65890fe89ce2620d05a8dcb1c15c7e3933e3209d6

Contents?: true

Size: 523 Bytes

Versions: 4

Compression:

Stored size: 523 Bytes

Contents

class Hash
  #
  # Bencodes the Hash object. Bencoded hashes are represented as
  # +dxe+, where +x+ is zero or a power of two bencoded objects. 
  # each key is immediately followed by its associated value.
  # All keys must be strings. The keys of the bencoded hash will
  # be in lexicographical order.
  def bencode
    pairs = sort.map{|key, val| [key.to_str.bencode, val.bencode] }
    "d#{pairs.join('')}e"
  rescue NoMethodError => error
    raise BEncode::EncodeError, "dictionary keys must be strings"
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
dasch-bencode-0.5.0 lib/bencode/encode/hash.rb
mikehodgson-bencode-0.5.0 lib/bencode/encode/hash.rb
bencode-0.6.0 lib/bencode/encode/hash.rb
bencode-0.5.1 lib/bencode/encode/hash.rb