Noob question:
class A; end
class B < A; end
B.kind_of?(A)
Is there a method that will return true if the class is a descendant of
that class?
Thanks for your help.
Noob question:
class A; end
class B < A; end
B.kind_of?(A)
Is there a method that will return true if the class is a descendant of
that class?
Thanks for your help.
On Tue, Sep 2, 2008 at 8:14 PM, Ben J. [email protected]
wrote:
Thanks for your help.
class A; end
class B < A; end
B.ancestors.include?(A)
=> true
Todd
2008/9/3 Ben J. [email protected]:
Noob question:
class A; end
class B < A; endB.kind_of?(A)
Is there a method that will return true if the class is a descendant of
that class?
class A; end
class B < A; end
B < A
=> true
Regards,
Park H.
From: Ben J. [mailto:[email protected]]
descendant is quite a generic term
compare,
B.ancestors.map {|b| [b, B < b]}
#=> [[B, false], [A, true], [Object, true], [Kernel, true]]
B.ancestors.map {|b| [b, B.superclass == b]}
#=> [[B, false], [A, true], [Object, false], [Kernel, false]]
kind regards -botp
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs