Forum: Ruby can't subclass XML::Document?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bc8e3e2f7acb3a7d93c10e235dc0b4e1?d=identicon&s=25 (Guest)
on 2007-04-19 15:55
(Received via mailing list)
I'm working with libxml and I can't seem to define a subclass of
XML::Document. For example,

require 'libxml'

class SubDocument < XML::Document
  def initialize(name)
    @sub_name = name

  def sub_method
    puts "the method"

> s ='test')
=> <?xml version="test"?>

> s.respond_to? 'sub_method'
=> false

> s.class
=> XML::Document

As you can see from the above, it's as if I'm aliasing XML::Document,
rather than subclassing it. I have also tried including XML and then
defining the subclass as well as opening the XML module and then
defining the subclass -- same results in both cases. I've never come
across this before. Is there a way to fix this or should I just write
my class to contain an XML::Document?

0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2007-04-19 17:55
(Received via mailing list)

In message "Re: can't subclass XML::Document?"
    on Thu, 19 Apr 2007 22:55:08 +0900, ""
<> writes:

|I'm working with libxml and I can't seem to define a subclass of

Probably, some extensions define their own "new" class method instead
of the "initialize" method.

This topic is locked and can not be replied to.