From: Gavin Kistner Date: 2004-02-17T22:51:48+09:00 Subject: Re: Hash like JS Hash (code) Claude Brisson wrote: > How would you achieve the same accesses with rexml elements, to access > subelements or attributes ? > > I guess it's possible, but I'm still a ruby newbie... Use the exact same code as I gave for the Hash object, but use the class of your choice there. (To make things really ugly, do this on Object, and EVERYTHING in Ruby will behave this way...at least, everything that supports the [] and []= methods :p) If you don't need setters, but only getters via dot notation, it can be simplified to: class SomeClass def method_missing(meth,*args) /=$/=~meth.id2name ? nil : self[meth] end end All this said, you should think hard before you do this, since it will make your code somewhat un-ruby-like; further, you run a strong risk of running into confusing problems, where you think you're accessing a property by name but are in fact invoking a method. -- (-, /\ \/ / /\/