|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi all
def OtherClass end def MyClass < OtherClass end 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? Thanks Josh -- Posted via http://www.ruby-forum.com/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Thank you very much! So very semantic and easy that I couldn't have
guessed it as a veteran PHP programmer... ;-) -- Posted via http://www.ruby-forum.com/. |
|
![]() |
| Outils de la discussion | |
|
|