From: Oliver Beddows Date: 2002-04-10T05:06:51+09:00 Subject: ruby + Creating and extending XML documents Hi, I am looking for some advice / opinion. I am currently developing a website using postgresql + ruby + xml and sablotron. A lot of the time each script on the site will require a set of common xml data. What follows below is my attempt at creating a class that will hold and display that data. Then for each page I simply extend the class to include new data. I`m pretty new to Object Orientation, so am I being naive? Is my approach totally off the mark? Have I been smoking too many drugs? Your opinions please! Regards, oliver@jellytone.com # For example, take the following xml document: A Page On My Site 1 oliver 12345678 staff true 99 # And in order to build that document I create this class: class MasterDocument def initialize @title = "No Title" end def document "#{data}" end def data [ title, user ] end def title=(newTitle) @title = newTitle end def title "#{@title}" end def user=(newUser) @user = newUser end def user if @user.nil? then @user = User.new end "#{@user.id}...etc...etc" end end # So when I need to create a document I do: xml = MasterDocument.new xml.title = "A Page On My Site" xml.user = user puts xml.document # And if I want the document to contain more data I do the following: class AnotherDocument < MasterDocument def initialize end def data super + [ some_data ] end def some_data=(newSomeData) @some_data = newSomeData end def some_data "#{@some_data}" end end # And to implement it I do: xml = AnotherDocument.new xml.title = "ruby review" xml.user = user xml.some_data = "ruby kicks ass" # Which gives me the following xml document: ruby review 1 oliver 12345678 staff true 99 ruby kicks ass