On Fri, Dec 09, 2011 at 02:58:18PM +0900, Andrew S. wrote:
> 
> I have a hash with various keys and values that are strings.
> 
> If the key exists, the following works: h["foo"] += "bar"
> 
> But if the key does not exist, I get an error.
> 
> Is it possible _in one statement_ to cover both the cases where the key
> does exist (as above) AND the case where the key does not exist - and in
> this situation I'd like the new key and value pair to be created in the
> hash.

I guess you could get really ugly with it.

    h['foo'] = h['foo'].to_s + 'bar'