You may be able to produce what you want by defining a module and extending the Document with it:

ardent:~ danj$ irb
irb(main):001:0> class A
irb(main):002:1> end
=> nil
irb(main):003:0> module B
irb(main):004:1> def hello
irb(main):005:2> puts "hello"
irb(main):006:2> end
irb(main):007:1> end
=> nil
irb(main):008:0> a=A.new
=> #<A:0x19256c>
irb(main):009:0> a.extend B
=> #<A:0x19256c>
irb(main):010:0> a.hello
hello
=> nil
irb(main):011:0>


You can also override #parse by renaming the original function and perform the extend after calling #parse_original.

Dan

On Aug 26, 2008, at 23:01, Mark Thomas wrote:

I'd like to create a subclass of XML::Document. However, I'm having trouble figuring out how I would instantiate my subclass because parsing requires Parser.parse() which returns an XML::Document instead of My::Subclass. Unfortunately, Ruby doesn't have a way of changing the class of an object.

Any suggestions?

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

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

Reply via email to