class String

Public Instance Methods

bdecode() click to toggle source

Bdecodes the String object and returns the data serialized through bencoding.

"li1ei2ei3ee".bdecode   #=> [1, 2, 3]
# File lib/bencode/core_ext/string.rb, line 21
def bdecode
  BEncode.load(self)
end
bencode() click to toggle source

Bencodes the String object. Bencoded strings are represented as x:y, where y is the string and x is the length of the string.

"foo".bencode   #=> "3:foo"
"".bencode      #=> "0:"
# File lib/bencode/core_ext/string.rb, line 11
def bencode
  "#{bytesize}:#{self}"
end