Ruby kind_of? and is_a? returning false for a subclass -


i'm trying take advantage of ruby methods kind_of? , is_a?. understand synonyms of 1 another.

i have object of class child. call child.ancestors gives array list [child, #<module>, parent, ...]. call child.new.is_a?(parent) or child.new.kind_of?(parent) returns false.

calling child.ancestors[2].new.is_a?(parent) returns false. can't seem figure out why considering calling parent.new.is_a?(parent) returns true should.

these classes descend activeresource::base if has it.

class parent < activerecord::base   include mymodule    def self.my_method(obj)      if obj.is_a?(parent)        puts 'hello'      end   end end  class child < parent   def my_method     self.class.my_method(self)   end end  = child.new  a.my_method 

class parent   def self.my_method(obj)     if obj.is_a?(parent)       puts 'is parent'     else       puts 'is not parent'     end   end end  class child < parent   def my_method     self.class.my_method(self)   end end  = child.new a.my_method 

note dropped ar , included module, above prints out "is parent" me. ruby 1.8.7 on osx.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -