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
のようにが参照されるsome_method
たびに を自動的に呼び出すことは可能ですか? によって暗黙的に呼び出されるようなものですが、より一般化されています。p
some_outside_method(p)
to_s
puts