2008/8/20 Charlie Savage <[EMAIL PROTECTED]>:
> This code:
>
> node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
>
> Generates this xml:
>
> puts node
> <foo><bar/>bars contents</foo>
>
> That is because the << returns self.
>
> Eric Musgrove if instead it should work like this (see
> http://rubyforge.org/tracker/?func=detail&atid=1971&aid=21424&group_id=494):
>
> puts node.parent.parent
>
> <foo>
>  <bar>bars contents</bar>
> <foo>
>
> By making the << operator return the appended node.
>
> << returning the appended node seems more useful, but doesn't follow the
> Ruby standard as pointed out by Masashi Shimbo.
>
> Thoughts?

The most general notion of #<< is "push", so this behvior makes sense
for anything that behaves like a stack. For XML which is a tree, it
does not make sense and I agree it would be better to return the
appended node.

T.
_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to