From: Sean Chittenden Date: 2001-11-14T09:40:46+09:00 Subject: [ruby-talk:25123] Re: REXML behavior change RFC > > Why not overload to_s so that it returns the first element, then > > overload to_a so that it'll return an array? If you know your data > > and know you only want one element, having it short-circuit the search > > is a Good Thing(TM) for performance. ;~) -sc > > Thanks, Sean. Err... you'll have to forgive my brain-o's below: > to_s currently returns the XML subtree, written out. EG: > > a = Element.new("a") > a.add_element "b" > a.to_s # -> "" How about having a method like: a.xpath("/foo/bar") -> XPath object w/ search loaded that returns an XPath object that has to_s and to_a overloaded (small wrapper around the Element class that only has to_s and to_a overloaded). When to_s or to_a is called, then it performs the search/scan of the document. > to_a returns all of the children. Although it would be pretty easy > to allow passing to_a an argument which is an XPath, this has the > same problem as passing each() an XPath, in that to_a doesn't > normally take arguments (in other core Ruby classes).