From: Gary Wright Date: 2007-10-10T03:35:00+09:00 Subject: Re: Indexers and blocks? On Oct 9, 2007, at 1:50 PM, Brian Adkins wrote: > c = MyClass.new('default') > c[:foo] = 'foo' > puts c[:foo] > puts c[:test] > c = MyClass.new {|obj,key| "default for #{key}" } > puts c[:test] This looks to me like you've just recreated features of Hash. Might as well just use Hash. I'd also like to point out Hash#fetch, which allows you to override the hash default logic: a = Hash.new(0) a[1] # 0 a.fetch(1) { |k| -k} # -1 a[1] # 0 a.fetch(1) # IndexError exception Gary Wright