C
Collins
I have a class hierachy that looks like this
class A
....
end
class B < A
....
end
class C < A
....
end
class D < B
....
end
class E < C
....
end
class F < B
....
end
Now class B has a method that expects either members of class D or E
or Fas a parameter but needs to do something different based upon the
whether the parameter is a subclass of B or a subclass of C.
I could check to see if it was D or F as opposed to B but that would
mean when I added class G<B...end I'd have to go back and touch B.
Is there a way to ask an object if it is descended from a particular
class? I suppose I could add a method to B and test for the presence
of that method in the parameter objects but that feels ucky.
Thanks
Collins
class A
....
end
class B < A
....
end
class C < A
....
end
class D < B
....
end
class E < C
....
end
class F < B
....
end
Now class B has a method that expects either members of class D or E
or Fas a parameter but needs to do something different based upon the
whether the parameter is a subclass of B or a subclass of C.
I could check to see if it was D or F as opposed to B but that would
mean when I added class G<B...end I'd have to go back and touch B.
Is there a way to ask an object if it is descended from a particular
class? I suppose I could add a method to B and test for the presence
of that method in the parameter objects but that feels ucky.
Thanks
Collins