method_missing(name, *args) 用法 Proxy

class User
class << self
    def say_hello(name)
        puts name + ' hello'
    end
end
end

class UserProxy
   # 加入类方法
    def self.method_missing(name, *args)
        User.send(name, *args)
    end
   
   # 加入实例方法
    def method_missing(name, *args)
        User.send(name, *args)
    end
end

UserProxy.say_hello('hlxwell')
up = UserProxy.new
up.say_hello('hlxwell')

你可能感兴趣的:(Ruby,UP)