Module: BEncode::List::Array::InstanceMethods

Defined in:
lib/bencode/list.rb

Instance Method Summary collapse

Instance Method Details

#bencode::String

Encodes an array into a bencoded list. Bencoded lists are encoded as an ‘l’ followed by their elements (also bencoded) followed by an ‘e’.

[:eggs, "ham", 3, 4.1].bencode #=> "l4:eggs3:hami3ei4ee"

Returns:

  • (::String)

    the bencoded list



45
46
47
48
49
# File 'lib/bencode/list.rb', line 45

def bencode
  collect do |element|
    element.bencode
  end.unshift(:l).push(:e).join
end