irb
module ParentModule; end
module ChildModule; end
class ParentClass
include ParentModule
end
class ChildClass < ParentClass
include ChildModule
end
child_instance = ChildClass.new
child_instance.is_a? ChildClass #=> true
child_instance.is_a? ParentClass #=> true
child_instance.is_a? Object #=> true
child_instance.is_a? String #=> false
child_instance.is_a? ParentModule #=> true
child_instance.is_a? ChildModule #=> true
--A direct instance of the class, or --An instance of that subclass, or --A class that includes a module, or a class --Returns true if it is an instance of that subclass (The meaning of is_a may be the meaning of is one of ~)
child_instance.instance_of? ChildClass #=> true
child_instance.instance_of? ParentClass #=> false
child_instance.instance_of? Object #=> false
child_instance.instance_of? String #=> false
child_instance.instance_of? ParentModule #=> false
child_instance.instance_of? ChildModule #=> false
Recommended Posts