J
James Byrne
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:
ocument", 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:
ocument". What
changes the ancestor of @forex_doc from Nokogiri::XML:
ocument to
Nokogiri::XML and removes the #xpath method? What is it about
inheritance/mixin am I not understanding?
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:
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:
changes the ancestor of @forex_doc from Nokogiri::XML:
Nokogiri::XML and removes the #xpath method? What is it about
inheritance/mixin am I not understanding?