method_missing and builder objects

Z

zuzu

jim weirich's got a hot example of using 'method_missing' to build XML
trees from defining methods in ruby objects. (idea originally from
groovy, the rubyish java bastard language.)

http://www.onestepback.org/index.cgi/Tech/Ruby/BuilderObjects.rdoc

"Ack, it's easy to see it in action than to describe it. For example,
the following code …

| builder = Builder::XmlMarkup.new("", 2)
| puts builder.person {
| name("jim")
| phone("555-1234", "local"=>"yes")
| address("Cincinnati")
| }

will print …

| <person>
| <name>jim</name>
| <phone local="yes">555-1234</phone>
| <address>Cincinnati</address>
| </person>

"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top