私はRubyMineIDEを使用しているので、使用方法がわからないためかもしれません。しかし、これが私が持っているものです:say_helloという名前のメソッドを持つMyFirstModuleという名前のモジュール
module MyFirstModule
def say_hello
puts 'Hello'
end
end
そしてまた、このようにそれを書いたクラス:
require 'MyFirstModule'
class ModuleTester
include MyFirstModule
end
mt = ModuleTester.new
mt.say_hello
次に、IDEを介してプログラムを実行すると、次のエラーが発生します。
/Users/Jony/.rvm/rubies/ruby-1.9.3-p374/bin/ruby -e $ stdout.sync = true; $ stderr.sync = true; load($ 0 = ARGV.shift)/ Users / Jony / RubymineProjects / Rubyist / play_one.rb /Users/Jony/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require'from
require': cannot load such file -- MyFirstModule (LoadError) from /Users/Jony/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
/ Users / Jony / RubymineProjects / Rubyist / play_one.rb:1:in load'from<top (required)>' from -e:1:in
-e:1:in `'