From: Joel VanderWerf Date: 2009-06-02T10:33:13+09:00 Subject: Re: Ruby enhancement suggestion Steve Hull wrote: > class Hash > def join(key_value_sep="=>", pair_sep=",") > result = "" > self.each { |k,v| result << k.to_s << key_value_sep << v.to_s << > pair_sep } > result.chomp pair_sep > end > end Not too hard in ruby: h = {:a => 1, :b => 2, :c => 3} p h.map{|pair| pair.join("=>")}.join(",") That's short enough that I wouldn't bother with a method, but if you prefer: class Hash def join(key_value_sep="=>", pair_sep=",") map{|pair| pair.join(key_value_sep)}.join(pair_sep) end end I guess the reason this isn't standard is that it is not very common (?) to treat the keys and values of a hash as strings, regardless of what they really are (note that the fact that keys are symbols is lost in the code above). -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407