L
Luke Graham
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>
<jim age="1"/>
<joe age="2"/>
</bar>
<bar/>
</foo>
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?
PS. Extra kudos if someone implements not only the above, but foo.bar
{ ... }, where foo and bar are methods...
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>
<jim age="1"/>
<joe age="2"/>
</bar>
<bar/>
</foo>
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?
PS. Extra kudos if someone implements not only the above, but foo.bar
{ ... }, where foo and bar are methods...