相关疑难解决方法(0)

如何使用define_method创建类方法?

如果您尝试以元编程方式创建类方法,这将非常有用:

def self.create_methods(method_name)
    # To create instance methods:
    define_method method_name do
      ...
    end

    # To create class methods that refer to the args on create_methods:
    ???
end
Run Code Online (Sandbox Code Playgroud)

我的回答是......

ruby metaprogramming class-method

106
推荐指数
5
解决办法
4万
查看次数

标签 统计

class-method ×1

metaprogramming ×1

ruby ×1