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.
···
--
Posted via http://www.ruby-forum.com/.
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.
--
Posted via http://www.ruby-forum.com/.
class A; end
class B < A; end
B.ancestors.include?(A)
=> true
Todd
On Tue, Sep 2, 2008 at 8:14 PM, Ben Johnson <bjohnson@contuitive.com> wrote:
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?Thanks for your help.
class A; end
class B < A; end
B < A
=> true
Regards,
Park Heesob
2008/9/3 Ben Johnson <bjohnson@contuitive.com>:
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?
# Is there a method that will return true if the class is a
# descendant of that class?
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
From: Ben Johnson [mailto:bjohnson@contuitive.com]