Okay, I thought I understood modules. Then I try to factor out some
common ‘utility’ methods into a separate file so that I don’t have to
mock up some silly inheritance hierarchy just to share functions like
AddHref(below). But apparently I don’t understand how names
propogate. I figured that inside TestHarness::Bah, if it couldn’t
resolve the name in Bah, it would look next in TestHarness, and then
in the global namespace. Did I err? If so, how can I get what I
want? Do I need to introduce an artificial inheritance here, or is
there a way I’m not seeing to share the code?
Thanks,
-=Eric
$ cat testharness.rb
module TestHarness
def AddHref(url, text)
"#{text}"
end
end
$ cat testview.rb
require ‘testharness’
module TestHarness
class Bah
def myprint
puts AddHref(‘http://www.google.com/’, ‘Google’)
end
end
end
TestHarness::Bah.new.myprint
$ ruby testview.rb
testview.rb:6: in ‘myprint’: undefined method ‘AddHref’ for #TestHarness::Bah:0x4024e7e8 (NameError)
from testview.rb:11
-=Eric
···
–
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton