From: Michael Edgar Date: 2011-03-04T02:48:10+09:00 Subject: Re: How to assign an element to a hash only if its value is not nil? Whoa, whoops, completely misread that. Early morning e-mail, disregard. Michael Edgar adgar@carboni.ca http://carboni.ca/ On Mar 3, 2011, at 12:46 PM, Gary Wright wrote: > > On Mar 3, 2011, at 12:38 PM, Michael Edgar wrote: > >> If you don't mind also overwriting the value if the value is false as well as if the value is nil, >> you can use the common ||= approach: >> >> hash[:key] ||= myvalue > > > That is different than what the OP described as it depends on the existing value of hash[:key] but the OP wanted the assignment conditional on the new value ('myvalue'). > > Gary Wright