From: "trans." Date: 2005-01-22T05:45:57+09:00 Subject: Re: Xpath like syntax Aredridel wrote: > On Sat, 22 Jan 2005 04:25:57 +0900, trans. wrote: > > Traversable mixin! That would be great! > > Would a single method, traverse_component be sufficient to build an > implementation on, do you think? Pass it a path component, and have the > object return whatever makes sense? (for a hash or array, map it to []; > for Objects in general, map it to send?) I'd think so. And I think it can be kept reasonably simple -- just #traverse or #travel or something like that should suffice. The return value may be better as the special object (what itisme213 is calling Q) so that it could be further queried/filtered, and also operated on "element-wise" (i.e. all the elements could be modified in parallel). Or maybe have two methods, one returns another "Q" and the other "whatever makes sense" (with the Q object another method, say #value, could return "wahtever made sence). Basically thinking out loud here. Playing with some code will probably reveal much more. > Perhaps have a second method, traverse_filter, that receives an array of > filters, for XPath-style qualifications like [@attr = 'foo'], or > [/childobject]? If a path is a string (?) and filters are always in an array, the differnce in class may allow for use of the same method, instead have having two separate methods. But having two merthods is okay if need be too. > My uses are, right now, for passing an object graph as model data to an > XTemplate view (something that Amrita does, and XTemplate does not, > yet), and for mapping a rails-style URL to an object graph of handlers > -- so that /foo/bar/baz maps to (roughly) startingpoint.foo.bar.baz I see. Looks like some very good use cases.