# Ara's double\_x : generate xml?

**URL:** <https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046>\
**Category:** Ruby\
**Created:** [March 27, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046 "2006-03-27T17:00:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/1 "2006-03-27T17:00:46Z")

</div>

Does this library support generating of xml (not xhtml)? what’s the top  
level call? I tried

xml\_ { …} and it dies with  
irb(main):021:0\> doc = xml\_ { p\_ “a” }  
NoMethodError: undefined method `create' for nil:NilClass from c:/ruby/lib/ruby/gems/1.8/gems/xx-0.1.0/lib/xx.rb:197:in`method\_missing’  
from (eval):10:in `xml_' from c:/ruby/lib/ruby/gems/1.8/gems/xx-0.1.0/lib/xx.rb:208:in`send’  
from c:/ruby/lib/ruby/gems/1.8/gems/xx-0.1.0/lib/xx.rb:208:in  
`method\_missing’  
from (irb):21  
from :0  
irb(main):022:0\>

Thanks.

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/2 "2006-03-27T17:05:55Z")

</div>

On Mon, 27 Mar 2006, itsme213 wrote:

> ```
> from c:/ruby/lib/ruby/gems/1.8/gems/xx-0.1.0/lib/xx.rb:208:in
> 
> ```
> 
> `method\_missing’  
> from (irb):21  
> from :0  
> irb(main):022:0\>
> 
> Thanks.

you just need to mixin the method you want, in this case the xml  
methods:

harp:~ \> cat a.rb  
require ‘xx’  
include XX::XML

puts xml\_{ p\_{ “a” } }  
harp:~ \> ruby a.rb

 \<?xml version='1.0'?\>

a

regards.

-a

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/3 "2006-03-27T17:14:47Z")

</div>

thank you sir. love the library. is the ‘\_’ convention something that is  
(or  
should be) configurable?

i’m also looking forward to experimenting with traits. it sounds like  
something that could be used for recording meta-data in lots of places,  
including things like nitro/og.

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 6:15pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/4 "2006-03-27T18:15:24Z")

</div>

On Tue, 28 Mar 2006, itsme213 wrote:

> thank you sir. love the library. is the ‘\_’ convention something that is (or  
> should be) configurable?

it is actually configurable. you do something like

xx\_configure “method\_missing”, XX::STRICT # tag methods  
require ‘_’  
xx\_configure “method\_missing”, XX::CRAZY\_LIKE\_A\_HELL # tag methods no  
not require '_’

in your class.

you example is a great example of why **not** to do that however,  
without the  
‘\_’ this

xml{ p ‘a’ }

would call ruby’s built-in ‘p’ method. this would fail, but silently.  
one of  
the big differences with xx and other html/xml generation libs is that  
it’s  
**designed** to be mixed into other classes to give them html generation  
capbilities (a la widgets). the thing is, when you mixin to a class  
like,  
say, Array, you’ve already lost a huge part of you namespace like  
‘length’,  
‘find’, ‘each’, etc. none of these methods will trigger method missing  
and so  
cannot be tag methods. this is less a big deal for html than for xml,  
which  
can contain pretty much anything as tag names. if one uses a blanket  
method  
missing approach, or even a receiver as the tag generator, one simply  
cannot  
generate xml using

o.type{ } # oops, all object have ‘type’  
o.id{ } # oops, all object have ‘id’

you can use a BlankSlate here… but then you’ve also lost the ability  
to  
mixin rather than agregate.

> i’m also looking forward to experimenting with traits. it sounds like  
> something that could be used for recording meta-data in lots of places,  
> including things like nitro/og.

for sure. it’s one of the things it was designed for. being able to  
get  
back list of traits is very valuable.

for instance, this line, taken from an ‘initialize’ method, iterates  
over all  
of this object’s class traits and creates an instance trait for the  
current  
object that gets a deep copy of the class trait as the default value:

klass = self.class  
mcp = lambda{|obj| Marshal::load(Marshal::dump(obj))}  
klass::class\_traits.each{|r,w| klass::trait®{ mcp[klass.send®]}}

so basically it says : “i have all the same traits as my class and i’ll  
bootstrap myself from the values of those traits which have been  
parameterized  
in my class”

this reason this is done is that this class is part of a hierarchy where  
each  
subclass adds more traits to parameterize the class. with this generic  
line i  
can make any instance of that subclass bootstrap properly with no new  
code.  
so

class Parent  
class\_trait ‘p’ =\> 42  
def intialize  
…  
end  
end  
class Child \< Parent  
class\_trait ‘c’ =\> 42.0  
end

child = Child::new

and here ‘child’ would have the **instance** traits ‘a’ and ‘b’ with  
default  
values gotten from the class method.

regards.

-a

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 7:14pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/5 "2006-03-27T19:14:06Z")

</div>

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message

> it is actually configurable. you do something like

I did not mean a blanket method\_missing. My real question was:

- if I have a conflict with the ‘\*\_’ convention, &
- I have another convention that I’d like to use e.g. ‘\*\_x’  
would I be able to configure to use that convention?

> this reason this is done is that this class is part of a hierarchy where  
> each  
> subclass adds more traits to parameterize the class.

Is it possible to have different ways of combining up the class/module  
chains? e.g. override? append? other?

Thanks!

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/6 "2006-03-27T19:28:19Z")

</div>

On Tue, 28 Mar 2006, itsme213 wrote:

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message
> 
> > it is actually configurable. you do something like
> 
> I did not mean a blanket method\_missing. My real question was:
> 
> - if I have a conflict with the ‘\*\_’ convention, &
> - I have another convention that I’d like to use e.g. ‘\*\_x’  
> would I be able to configure to use that convention?

ah. no. however, it would be a 3 minute exercise to add this  
capability.  
would you like me too?

> > this reason this is done is that this class is part of a hierarchy where  
> > each subclass adds more traits to parameterize the class.
> 
> Is it possible to have different ways of combining up the class/module  
> chains? e.g. override? append? other?

hmm. override is the default. let me think about append.

regards.

-a

---

<div class="post-metadata">

**Author:** ![itsme213](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/258eb7/32.png) [@itsme213](https://www.ruby-forum.com/u/itsme213)\
**Post date:** [March 27, 2006, 10:19pm UTC](https://www.ruby-forum.com/t/aras-double-x-generate-xml/56046/7 "2006-03-27T22:19:12Z")

</div>

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message

> ah. no. however, it would be a 3 minute exercise to add this capability.  
> would you like me too?

If you think it would be generally useful. For right now I’m fine with  
‘\_’.

> > Is it possible to have different ways of combining up the class/module  
> > chains? e.g. override? append? other?
> 
> hmm. override is the default. let me think about append.

A trait of a trait, perhaps 😉
