Module: BEncode::List

Defined in:
lib/bencode/list.rb

Defined Under Namespace

Modules: Array, Generic

Class Method Summary collapse

Class Method Details

.register(type) ⇒ Object

Registers a class as an object that can be converted into a bencoded list. Class must have instance method to_a or to_ary.

class MyClass
  def to_a
    [1, :cat]
  end
end

BEncode::Integer.register MyClass
my_class = MyClass.new
my_class.bencode  #=> "li1e3:cate"

Parameters:

  • type (Class#to_a, Class#to_ary)

    the class to add the bencode instance method to



33
34
35
# File 'lib/bencode/list.rb', line 33

def self.register(type)
  type.send :include, Generic::InstanceMethods
end