我有几个类,例如,P共享相同的实例方法some_method:
class P
...
def some_method
@id
end
end
这些类的实例将在许多地方用作参数,如下所示:
p = P.new
q = Q.new
...
def some_outside_method(p,q,r,s)
another_outside_method(p.some_method, q.some_method, r.some_method, s.some_method)
end
我想知道是否有更优雅的写作方式。是否可以在引用时自动调用p's ?它类似于隐式调用 by ,但更通用。some_methodpsome_outside_method(p)to_sputs