LoginSignup
1
1

More than 5 years have passed since last update.

[Ruby]オーバーライドしたメソッドをスーパークラスのメソッドから呼んだ時の動き

Last updated at Posted at 2017-11-24

ソース

class TestClass
  def method1
    p("this is TestClass#method1")
  end

  def run
    method1
  end
end

class TestClass2 < TestClass
  def method1
    p("this is TestClass2#method1")
  end
end

TestClass2.new.run

実行結果

"this is TestClass2#method1"

サブクラスのメソッドが呼ばれる。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1