Module: BEncode::Dictionary

Defined in:
lib/bencode/dictionary.rb

Defined Under Namespace

Modules: Generic, Hash

Class Method Summary collapse

Class Method Details

.register(type) ⇒ Object

Registers a class as an object that can be converted into a bencoded dictionary. Class must have instance method to_h or to_hash.

class MyClass
  def to_h
    {:a => :a, :b => 1}
  end
end

BEncode::String.register MyClass
my_class = MyClass.new
my_class.bencode  #=> "d1:a1:a1:bi1ee"

Parameters:

  • type (Class#to_h, Class#to_hash)

    the class to add the bencode instance method to



34
35
36
# File 'lib/bencode/dictionary.rb', line 34

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