Class: String
- Defined in:
- lib/bencode/decode.rb,
lib/bencode/core_ext/string.rb
Instance Method Summary collapse
-
#bdecode ⇒ Object
Bdecodes the String object and returns the data serialized through bencoding.
-
#bencode ⇒ Object
Bencodes the String object.
Instance Method Details
#bdecode ⇒ Object
Bdecodes the String object and returns the data serialized through bencoding.
"li1ei2ei3ee".bdecode #=> [1, 2, 3]
45 46 47 |
# File 'lib/bencode/decode.rb', line 45 def bdecode BEncode.load(self) end |
#bencode ⇒ Object
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:"
11 12 13 |
# File 'lib/bencode/core_ext/string.rb', line 11 def bencode "#{length}:#{self}" end |