# Trouble with module/class inheritance

**URL:** <https://www.ruby-forum.com/t/trouble-with-module-class-inheritance/166181>\
**Category:** Ruby\
**Created:** [April 22, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/trouble-with-module-class-inheritance/166181 "2009-04-22T16:32:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 22, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/trouble-with-module-class-inheritance/166181/1 "2009-04-22T16:32:23Z")

</div>

I have a class “ForexCASource” that does this:

class ForexCASource  
include Nokogiri::XML

def initializer(…  
…  
return xchg\_source  
end

# Takes an xml source, default set to FOREX\_SITE

# Returns a nokogiri xml document object

def xchg\_source(source=FOREX\_SITE)  
@forex\_doc = Nokogiri::XML(open(source))  
rescue Exception =\> e  
puts e  
Rails::logger.error(“ForexCASource unable to read #{source} \n  
#{e}”)  
raise e  
end  
…

When new is called on this class (fx\_xml\_doc = ForexCASource.new) then I  
expect to receive @forex\_doc, which has a class of  
“Nokogiri::XML::Document”, and an inherited public method ‘#xpath’.

However, while the returned object has class ForexCASource, which is to  
be expected, I do not get the #xpath method attached to the returned  
object, which is not what I expected.

When I examine the returned object then I see:

puts fx\_xml\_doc.class.ancestors  
ForexCASource  
Nokogiri::XML  
Object

This is critically different than “Nokogiri::XML::Document”. What  
changes the ancestor of @forex\_doc from Nokogiri::XML::Document to  
Nokogiri::XML and removes the #xpath method? What is it about  
inheritance/mixin am I not understanding?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 22, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/trouble-with-module-class-inheritance/166181/2 "2009-04-22T16:41:06Z")

</div>

James B. wrote:

> This is critically different than “Nokogiri::XML::Document”. What  
> changes the ancestor of @forex\_doc from Nokogiri::XML::Document to  
> Nokogiri::XML and removes the #xpath method? What is it about  
> inheritance/mixin am I not understanding?

I implemented my own xpath method which calls  
Nokogiri::XML::Document.xpath on the internal instance variable  
@forex\_doc. This has resolved my problem.
