我正在try 使用Ruby模块(mixin).
我有考试.rb:
#!/usr/bin/env ruby
require_relative 'lib/mymodule'
class MyApp
include MyModule
self.hallo
end
和lib/mymodule.rb:
module MyModule
def hallo
puts "hallo"
end
end
设置非常简单.但它不起作用:(:
ruby test.rb
test.rb:8:in `<class:MyApp>': undefined method `hallo' for MyApp:Class (NoMethodError)
from test.rb:6:in `<main>'
我的错误在哪里?