假设我有一个类在 rubyCaller
中调用另一个类的方法(即):Abc
class Caller
def run
abc = Abc.new
abc.method1
abc.method2
end
end
class Abc
def method1
puts 'Method1 etc'
end
def method2
puts 'Method2 etc'
end
end
caller = Caller.new
caller.run
每次Abc
调用类中的方法时,我都需要使用显示Calling
方法类名称和方法名称的前缀来装饰调用例如在上面的示例中,我需要以下输出:
Caller.run - Method1 etc
Caller.run - Method2 etc
在红宝石中执行此操作的最佳方法是什么?