Say I've got a file 'dummy.rb' like this:
-----------------------------------------------------
module Dummy
def TryMe
puts "yo"
end
end
-----------------------------------------------------
Now, I try and run this program, called 'testdummy.rb':
-----------------------------------------------------
#!/usr/bin/env ruby
require 'dummy'
include Dummy
TryMe()
def main
TryMe()
end
main()
-----------------------------------------------------
I get, as expected:
----------
yo
yo
----------
Now, I try and run this program, called 'testdummy2.rb':
-----------------------------------------------------
#!/usr/bin/env ruby
require 'dummy'
Dummy::TryMe()
def main
Dummy::TryMe()
end
main()
----------------------------------------------------
I get:
-----------------
testdummy2.rb:3: undefined method `TryMe' for Dummy:Module (NoMethodError)
-----------------
Now, if I go ahead and change the 'dummy.rb' module to look like this:
----------------------------------------------------
module Dummy
def self.TryMe
puts "yo"
end
end
----------------------------------------------------
testdummy2.rb gives me:
------------------------
yo
yo
------------------------
and testdummy.rb gives me:
------------------------
testdummy.rb:4: undefined method `TryMe' for main:Object (NoMethodError)
------------------------
QUESTION: How can I create module 'Dummy' so that it can be called
either with the syntax in 'testdummy.rb' or 'testdummy2.rb' without
modification?
Thanks!
-- Glenn