From: "Peña, Botp" Date: 2007-10-31T11:06:22+09:00 Subject: Re: Array and ASCII Help needed... From: MenTaLguY [mailto:mental@rydia.net] # On Wed, 31 Oct 2007 05:58:32 +0900, 7stud -- # > Martin DeMello wrote: # >> a ||= b is a common ruby idiom for "set a to b only if it isn't # >> already defined" - # >> it expands to a = a || b. # > Nope. What do you think the following will output: # > h = Hash.new('hi') # > h['a'] = h['a'] || 10 # > puts h['a'] # > Now, how about the following? The same output as above? # > h['a'] ||= 10 # > puts h['a'] # # Actually, yes. They give the same results. Try it yourself... i think 7stud meant this, ~> h=Hash.new("hi") => {} ~> h => {} ~> h['a']=h['a'] || 10 => "hi" ~> h => {"a"=>"hi"} ~> h['b'] ||= 10 => "hi" ~> h => {"a"=>"hi"} kind regards -botp