lib/bencodr/parser.rb in bencodr-1.0.1 vs lib/bencodr/parser.rb in bencodr-1.1.0

- old
+ new

@@ -108,6 +108,20 @@ [key, value] end private :parse_key_value end end +end + +class String + # This method decodes a bencoded string into a ruby object. + # + # "6:string".bdecode #=> "string" + # "i-1e".bdecode #=> -1 + # "le".bdecode #=> [] + # "de".bdecode #=> {} + # + # @return [::String, ::Integer, ::Array, ::Hash] the decoded object + def bdecode + BEncodr::Parser.parse_object(StringScanner.new self) or raise BEncodr::BEncodeError, "Invalid bencoding" + end end \ No newline at end of file