Module: BEncode::String

Defined in:
lib/bencode/string.rb

Defined Under Namespace

Modules: Generic, String

Class Method Summary collapse

Class Method Details

.register(type) ⇒ Object

Registers a class as an object that can be converted into a bencoded string. Class must have instance method to_s or to_str.

class MyClass
  def to_s
    "string"
  end
end

BEncode::String.register MyClass
my_class = MyClass.new
my_class.bencode  #=> "6:string"

Parameters:

  • type (Class#to_s, Class#to_str)

    the class to add the bencode instance method to



35
36
37
# File 'lib/bencode/string.rb', line 35

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