From: Daniel Schierbeck Date: 2006-05-23T20:31:23+09:00 Subject: Re: initializing instance variables in a module Simon Kr�ger wrote: > module Foo > def bar(key) > @myvar ||= Hash.new {|k,v| k[v] = []} > @myvar[key] > end > end > > class Test > include Foo > end > > t = Test.new > t.bar('baz') << 'eeek' > p t.bar('baz') Why not just module Foo def bar @bar ||= Hash.new{|hsh, key| hsh[key] = []} end end class Test include Foo end test = Test.new test.bar[:baz] << 'bur' `a ||= b' returns `a' or, if `a' is nil, `b'. Daniel