0
0

More than 5 years have passed since last update.

Rubyでオブジェクトのクラスを調べる方法

Last updated at Posted at 2019-03-19

classメソッド

レシーバ

任意のオブジェクト

戻り値

レシーバが所属しているClassクラスのオブジェクト


irb(main):001:0> String.class
=> Class

superclassメソッド

レシーバ

Classクラスのオブジェクト

戻り値

レシーバが所属しているクラスの親クラスのClassクラスのオブジェクト


irb(main):002:0> String.superclass
=> Object

ancestorsメソッド

レシーバ

Classクラスのオブジェクト

戻り値

レシーバのクラスの継承しているクラス及びモジュールが全て入った配列


irb(main):003:0> String.ancestors
=> [String, Comparable, Object, Kernel, BasicObject]
0
0
2

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
0
0