Joel VanderWerf
11/4/2007 11:19:00 PM
Joshua Muheim wrote:
> How can I check if MyClass extends OtherClass? When I have an instance I
> can call my_class_instance.kind_of?(OtherClass), but what can I call
> when only having the class name?
Use the #< and #<= methods of classes (and modules):
class OtherClass
end
class MyClass < OtherClass
end
classes = [MyClass, OtherClass]
classes.each do |c1|
classes.each do |c2|
puts "#{c1} < #{c2}" if c1 < c2
puts "#{c1} <= #{c2}" if c1 <= c2
end
end
__END__
Output:
MyClass <= MyClass
MyClass < OtherClass
MyClass <= OtherClass
OtherClass <= OtherClass
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407