-3

B以下の例では、インスタンス化されるたびに作成/設定されるクラスにインスタンス変数が必要ですBinitialize明らかに、のすべてのメソッドを再定義する必要はありませんA

class A

  def initialize(a)
  end

  def initialize(a, b)
  end

end

class B < A
  # Here I want an instance variable created without
  # redefining the initialize methods

  @iv = "hey" #<-- Obviously does not work

  # And I don't want to have to do @iv |= "hey" all over the place

end
4

1 に答える 1