From: Stefan Lang Date: 2005-10-22T04:16:16+09:00 Subject: Re: Module question - should be simple, but can't figure it out... On Friday 21 October 2005 21:06, Glenn M. Lewis wrote: [...] > Now, I try and run this program, called 'testdummy.rb': > ----------------------------------------------------- > #!/usr/bin/env ruby > require 'dummy' > include Dummy > TryMe() > def main > TryMe() > end > main() [...] > Now, I try and run this program, called 'testdummy2.rb': > ----------------------------------------------------- > #!/usr/bin/env ruby > require 'dummy' > Dummy::TryMe() > def main > Dummy::TryMe() > end > main() > ---------------------------------------------------- [...] > 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? Option 1) module Dummy def TryMe puts "yo" end # Add all instance methods of the Dummy module to # the Dummy module object (here referenced as "self"). extend self end Option 2) module Dummy def TryMe puts "yo" end # give all method names (as symbols) as argument # to module_function module_function :TryMe, :SomeOtherMethod end HTH, Stefan