From: Brian Candler Date: 2008-11-10T07:12:30+09:00 Subject: Re: changing the value of a hash Jf Rejza wrote: > I want to change the value of > the key called "mail". I'd probably just write something simple like: h = s.attributes h['mail'].gsub!('@',' (at) ') if h['mail'] If you really want to iterate, then h = s.attributes h.each { |k,v| h[k] = v.gsub('@',' (at) ') if k=='mail' && v } And if you want to write it as a one-liner, look at inject or merge. If you know there's always a mail attribute, then: s.attributes.merge( 'mail' => s.attributes['mail'].gsub('@',' (at) ' ).to_json -- Posted via http://www.ruby-forum.com/.