lib/bencoding/hash.rb in simonmenke-bencoding-0.0.3 vs lib/bencoding/hash.rb in simonmenke-bencoding-0.0.4

- old
+ new

@@ -1,10 +1,18 @@ module Bencoding module Hash def to_bencoding - "d"+sort{|a,b|a[0].to_s<=>b[0].to_s}.collect{|key, item|key.to_bencoding+item.to_bencoding}.join+"e" + return '' if empty? + data = sort{|a,b|a[0].to_s<=>b[0].to_s}.collect do|key, item| + unless (item_data = item.to_bencoding).nil? + key.to_bencoding+item.to_bencoding + else + '' + end + end.join + "d"+data+"e" end end end