You need a require file before you can use the types defined in it. *
# my_first_module.rb module MyFirstModule def say_hello puts 'hello' end end
Pay attention to require at the beginning of the following:
# module_tester.rb require 'my_first_module' class ModuleTester include MyFirstModule end mt = ModuleTester.new mt.say_hello
The require method actually loads and executes the specified script using the Ruby VM boot path ( $: or $LOAD_PATH ) to find it when the argument is not an absolute path.
The include method, on the other hand, actually mixes the current class in the Module methods. It is closely related to extend . The Well Grounded Rubyist does a great job of all this, so I urge you to continue to connect to it.
See # require , # include, and # expand docs for more information.
* When using Rubygems and / or the Bundler , but getting into these details is likely to confuse you more than it costs at this point.
krohrbaugh
source share