Ruby 模块中的别名单例方法

Ruby 模块中的别名单例方法,ruby,module,aliasing,Ruby,Module,Aliasing,我有一个名为Setup的模块,希望为一个方法添加别名 这是它的外观,但它不起作用: module Setup def Setup::option_set?(option) #... end alias :option_set? :get_information end 我想这与设置::-前缀有关。怎么办?模块设置 module Setup class << self def option_set?(option) #... end

我有一个名为
Setup
的模块,希望为一个方法添加别名

这是它的外观,但它不起作用:

module Setup
  def Setup::option_set?(option)
    #...
  end
  alias :option_set? :get_information
end
我想这与
设置::
-前缀有关。怎么办?

模块设置
module Setup
  class << self
    def option_set?(option)
      #...
    end
    alias :get_information :option_set? 
  end
end

类您是否尝试丢失前缀?那么我无法访问这些方法。。。通过尝试和错误学习了这一部分你先来:)!完全正确
option\u set?
是一个单例方法,要生成别名,必须在
类中进行。不,它不应该是类,我这里不需要类,只需要一个通用名称空间下的方法集合……在写完我的注释后,看到了Gerry的注释。。。这样我就可以手动地给它取别名了,如果我必须动态地给它取别名呢?假设我希望用户重命名其名称作为参数传递的方法?