我有一个常量的ruby模块。它有一个变量列表和一个应用格式化的方法。我似乎无法访问此模块中的方法。知道为什么吗?
发布于 2011-03-24 18:16:31
module Foo
def self.hello # This is a class method
puts "self.hello"
end
def hello # When you include this module, it becomes an instance method
puts "hello"
end
end
Foo.hello #=> self.hello
class Bar
include Foo
end
Bar.new.hello #=> hello
发布于 2011-03-24 17:50:18
一般来说,对于模块,这些事情应该会发生:
application.rb中的->自动加载路径,添加行:
config.autoload_paths += %W(#{config.root}/lib)
/lib中的-> Place模块
->包含带有“Include NAMEOFMODULE”的模块
(如果模块有一个像game_engine这样的下划线,你需要‘包括GameEngine')
https://stackoverflow.com/questions/5417209
复制相似问题