From: Robert Klemme Date: 2005-04-11T16:49:37+09:00 Subject: Re: groovy-like xml selection "Luke Graham" schrieb im Newsbeitrag news:c6afaed005041020493e803be4@mail.gmail.com... > Hi list, > > Ive taken a quick look at groovy for the first time, and saw an > interesting idea. Using xml to build an object tree, its possible to > write code like this... > > > > > > > > > > foo.bar.star.select { |it| it[@age] == "1" && it.parent.name == "bar" > && it.star.count == 0 } > > Note that foo.bar and foo.bar.star are not arrays, rather > transparently hide multiple elements in one object. Requesting a value > would be handled by the first element. > > The interesting part is that theres no quotes around the path > expression, its just evaluated in the context of bar. Complex > expressions could be broken into multiple selects and combined with > normal array operations. > > Im sure someones done the xml->object (method in this case) thing, but > has the native path trick been tried in ruby yet? REXML comes pretty close. I'm sure with a small addition like this one you get pretty far: class REXML::Element def method_missing(sym,*a,&b) elements[sym.to_s] or super end end Maybe you should add this to module REXML::Node. > PS. Extra kudos if someone implements not only the above, but foo.bar > { ... }, where foo and bar are methods... Dunno what you mean here. foo and bar have to be methods. Regards robert