On Thu, 23 Mar 2006 03:28:25 -0000, zdennis <[EMAIL PROTECTED]> wrote:
> Mark Van Holstyn wrote:
>> Here is my suggestions for the API. Let me know what you think.
>>
>
> I think Mark's document makes alot of sense. I am using Marks changes
> currently (patched 0.3.6) and
> I love the method 'first' that he has added to XML::Node.
>
> I fully agree that removing Node::Set in favor or an Array would make
> the API more powerful.
> Currently if I want to sort some nodes I have to put them in some other
> data structure. Ie:
>
> array = []
> node.find( 'Child1/Child2' ).each { |e| array << e }
> array.sort{ |a,b| a.meth <=> b.meth }
>
> IMO, it is so much nicer to say:
>
> node.find( 'Child1/Child2' ).sort{ |a,b| a.meth <=> b.meth }
>
I fully agree with this (and many of the other changes Mark proposed), but
I disagree that replacing Node::Set etc with an Array is the way to go -
bear in mind that libxml-ruby (like libxml) is built for speed and will
hopefully stay that way. I tend to favour keeping things much as they are,
just using the power of Ruby to build on it.
See [1] for some experiments I did to this end a while back. Mostly we can
get big benefits by just including Enumerable in a few places, and
defining some new convenience methods here and there (obviously from C,
the Ruby code I showed just prototypes it. Also, ignore the mention of
segfault bugs which have since been cleared).
Do note, however, that to_a already works as you'd (probably) expect on
node, so you could replace the above with e.g.:
node.find('Child1/Child2').to_a.sort { |a,b| ... }
or
[*node.find('Child1/Child2')].sort { |a,b| ... }
> On a side note. Since I will be using libxml as well =) I can throw up a
> Trac site for libxml-ruby
> if the team would like to use it. Currently we host for rubyeclipse as
> well
> (http://rubyeclipse.mktec.com)
From my point of view, I'm behind with docs as it is and have plenty to do
on the code, so it's probably not the right time to do that. Once we get
the next round of releases out the way, and things are calmer, it would
probably be a great idea :).
[1]:
http://rubyforge.org/pipermail/libxml-devel/attachments/20051230/778cd254/libxml-x.obj
--
Ross Bamford - [EMAIL PROTECTED]
_______________________________________________
libxml-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/libxml-devel