Hi --

On Mon, 2 Jun 2008, David Masover wrote:

> On Friday 30 May 2008 18:21:51 David A. Black wrote:
>> Hi --
>>
>> On Fri, 30 May 2008, Mark Wilden wrote:
>>
>>> On May 29, 2008, at 3:37 AM, David A. Black wrote:
>>>
>>>> Duck typing, as a way of thinking, meshes nicely with Ruby, as a tool,
>>>> because of how Ruby objects are engineered: the *only* thing that you
>>>> can measure with certainty is what an object does when you send it a
>>>> message.
>>>
>>> No, you cannot possibly measure with certainty what an object does when
> you
>>> send it a message. The only thing you can measure is whether it will throw
> a
>>> runtime error because it doesn't implement a method for the message.
>>
>> I mean you can measure what it's done after it's done it. I don't mean
>> you can measure what it *will* do; that's precisely my point (you
>> can't).
>
> As long as we're nitpicking, you can't necessarily measure what's happened
> after the fact, either. The object may well swallow everything with
> method_missing and do nothing. It may be possible to play tricks with
> respond_to?, __send__, and so on, to achieve the same effect.

I'm thinking of the effect, though. When you send a message to an
object, something comes back, or an exception is raised. My point is
just that none of that can be known with certainty (I can't absolutely
know that a.b will return c, or an object of class D, or whatever)
before it happens.

> After all, your only way to check what goes on inside the class is to ask it,
> by sending a message.
>
> Of course, at this point, it doesn't really matter. Your definition of success
> is probably based on what your program actually does -- what it actually
> inputs and outputs -- and not on the internal state of some object.
>
>>> However, an object's class and ancestors _determine_ what messages an
> object
>>> responds to. That's what they're there for - to hold message maps.
>>
>> No; they determine what messages a freshly-minted object responds to.
>
> Unless I override #new, or #method_missing, or a number of other tricks.

It depends how you define "responds to". But mainly my point is that,
at most, the class tells you about the state of things at the birth of
the object -- the nature part, that is, but not the nurture part.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
See http://www.rubypal.com for details and updates!