From: Martin DeMello Date: 2006-12-01T21:35:42+09:00 Subject: Re: why does openstruct not respond to [] and []=? On 12/1/06, Robert Klemme wrote: > On 01.12.2006 13:14, Martin DeMello wrote: > > Took me aback - there seems to be no reason for OpenStruct *not* to > > permit member access via ostruct[:field] and ostruct['field']. > > OpenStruct also does not inherit Enumerable. I guess the story is, if > you need a Hash then use a Hash. The key point of OpenStruct is that > you can use arbitrary member setters and getters not indexed access. Is > there actually a situation where you need both? I was trying to collect all the binary options to my app in a hash (as being somewhat less verbose than the standard OptionParser syntax): { :verbose => ["-v", "--[no-]verbose", "run verbosely"], :all => ["-A", "--all", "select all files"], #.... }.each {|k,v| opt.on(*v) {|i| opts.send(:"#{k}=", i) } } The last line would have been a lot less ugly as opts[k] = i, and as I said, there seems no real reason not to allow it. martin