パンくず
Ruby Cookbook
オブジェクトのクラスと基底クラス
概要
オブジェクトのクラスと基底クラス
内容
オブジェクトのクラスはObject#class
基底クラスはClass#superclass
祖先のリストはModule#ancestors
で取得出来ます。
サンプルコード
# encoding: Windows-31J require "pp" class Hoge end class ExtendedHoge < Hoge end ex_hoge = ExtendedHoge.new pp ex_hoge.class pp ex_hoge.class.superclass pp ex_hoge.class.ancestors
出力
ExtendedHoge Hoge [ExtendedHoge, Hoge, Object, PP::ObjectMixin, Kernel, BasicObject]