现在我的代码是这样工作的:
def method_a
self.method_b ==> 'method_b'
end
def method_b
puts self.name_of_calling_method
end
def name_of_calling_method
if /`(.*)'/.match(caller.first)
return $1
else
return nil
end
end
我如何打印调用方法的名称“method_a”,而不是method_b打印“method_b”?
最佳答案
用caller.first
替换caller[1]
。