Class: Hash
Instance Method Summary collapse
-
#bencode ⇒ Object
Bencodes the Hash object.
Instance Method Details
#bencode ⇒ Object
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.
9 10 11 12 13 14 |
# File 'lib/bencode/core_ext/hash.rb', line 9 def bencode pairs = sort.map{|key, val| [key.to_s.bencode, val.bencode] } "d#{pairs.join}e" rescue NoMethodError => error raise BEncode::EncodeError, "dictionary keys must be strings" end |