Sha256: c9d9f82f1f359c0207e715ccf7e58fcaf8c765b225a33de58a5357542c650c99
Contents?: true
Size: 460 Bytes
Versions: 2
Compression:
Stored size: 460 Bytes
Contents
class BEncoder def self.encode(object) case object when Symbol encode object.to_s when String "#{object.length}:#{object}" when Integer "i#{object}e" when Array encoded_content = object.inject("l") { |result, el| result += encode(el) } encoded_content += "e" when Hash encoded = object.inject("d") { |result, (k,v)| result += "#{encode(k.to_s)}#{encode(v)}" } encoded += "e" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bencoder-0.0.1 | lib/bencoder.rb |
bencoder-0.0.0 | lib/bencoder.rb |