__getattr__在ruby中是否有等效的python (至少可以找到方法)?
class X(object):
def __getattr__(self, name):
return lambda x: print("Calling " + name + ": " + x)
x = X()
x.some_method("some args")
Run Code Online (Sandbox Code Playgroud)
所以它可能是这样的:
class X
# .. ??? ..
def default_action(method_name, x)
puts "Calling {method_name}: {x}"
end
end
x = X.new()
x.some_method("some args")
Run Code Online (Sandbox Code Playgroud) ruby ×1