From: Patrick Logan Date: 2001-06-26T23:41:56+09:00 Subject: [ruby-talk:16901] Re: Something strange with Ruby's inheritance mechanism "Eric Jacoboni" wrote in message news:863d8ntt5p.fsf@titine.fr.eu.org... > > That's exactly my problem : A is a subset of B. A subset of objects: a > A object is always a B object, the opposite is not necessary true. My > first post was about the lack of this concept in Ruby: dynamic typing > prevents it as an A object may become, say, an Integer. As beginner in > Ruby, the surprise comes from the fact that the OOP is ok as long as > we stay at the class level but disappears when we come to instances > (object) because of dynamic typing. This trouble comes from my > experience with strong typing languages. There are two things that make Ruby different from previous languages you appear to be accustomed to: (1) Variables do not have "types". So you have to lose the association between a variable and the kinds of objects it can refer to. (2) Ruby objects do not have associated "types". How an object can be used is dependent on the kinds of methods it has, not whether it is a subclass of this or that superclass. For example: class ObjectOne def frobnicate puts 1 end end class ObjectTwo def frobnicate puts "I am not a number. I am a Church numeral." end end one = ObjectOne.new two = ObjectTwo.new def doit(something) something.frobnicate end doit(one) doit(two) Results in: 1 I am not a number. I am a Church numeral. Even though the two objects are unrelated by class defiinition. -- Patrick Logan mailto:patrickdlogan@home.com