Module: BEncode::Dictionary::Generic::InstanceMethods

Defined in:
lib/bencode/dictionary.rb

Instance Method Summary collapse

Instance Method Details

#bencode::String

Encodes an array into a bencoded dictionary. Bencoded dictionaries are encoded as a ‘d’ followed by a list of alternating keys and their corresponding values followed by an ‘e’. Keys appear in sorted order (sorted as raw strings, not alphanumerics).

{:cow => "moo", :seven => 7}.bencode #=> "d3:cow3:moo5:seveni7ee"

Returns:

  • (::String)

    the bencoded dictionary



14
15
16
# File 'lib/bencode/dictionary.rb', line 14

def bencode
  (respond_to?(:to_h) ? to_h : to_hash).bencode
end