From: Robert Klemme Date: 2006-12-24T01:15:05+09:00 Subject: Re: Help with a ruby idiom On 23.12.2006 17:02, Tim Waters wrote: > From the O'Reilly Cookbook there is code that keeps call functions in a > hash as a subscriber/listener type pattern. What I don't understand (or > I don't understand how it works is the line: > (@EventDispatcher_listeners[event] ||= []) << callback a ||= b is equivalent to a || (a = b) IOW a = b unless a IOW unless a a = b end IOW "eval b and assign the result to a if a is nil or false". In this case, since a Hash is also involved the lengthy form looks like this: unless @EventDispatcher_listeners[event] @EventDispatcher_listeners[event] = [] end @EventDispatcher_listeners[event] << callback I hope you admit that ||= is much more concise and elegant. :-) HTH robert