Module: BEncode::Integer

Defined in:
lib/bencode/integer.rb

Defined Under Namespace

Modules: Generic, Integer

Class Method Summary collapse

Class Method Details

.register(type) ⇒ Object

Registers a class as an object that can be converted into a bencoded integer. Class must have instance method to_i or to_int.

class MyClass
  def to_i
    1
  end
end

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

Parameters:

  • type (Class#to_i, Class#to_int)

    the class to add the bencode instance method to



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

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