Hi --

On Tue, 14 Mar 2006, Bill Barnhill wrote:

> Oops, my apologies, forgot an end in example.
> Should read
> class B < A
>    def initialize
>       @a = "foo"
>    end
> end
>
> Another though on this is that it would allow us to define message
> interfaces (aka duck-typing prototypes).

I fear that  "duck-typing prototype" is a contradiction in terms.
With duck typing, you're dealing with an object: it's all about the
moment you send the message to the object, and the *absence* of
concern about where that object came from, what its pedigree is, and
so forth.  "Message interfaces" suggests a higher-level clustering of
behaviors.

> On 3/14/06, Bill Barnhill <xmlarchitect / gmail.com> wrote:
>>
>> Hmm, just some thoughts.
>> I think the abstract method idea nice in concept, but implementation
>> perhaps too Java-ish.
>>
>> If I get a chance later this week I'll code this, but for now here's how
>> I'd envision something like this within Ruby code:
>>
>> class A
>>     should_respond_to_behavior  #..options hash describing what to do if
>> msg not
>>                                                # responded to properly
>> goes here,
>>                                                # nice to support YAML as
>> well..
>>     should_respond_to :foo, :bar => {}, :baz => {:param_count => 3}
>> end
>>
>> class B < A
>>     def initialize
>>        @a = "foo"
>> end
>>
>> B.new
>> =begin
>> At this point the class a checks responses:
>> .. it expects a response to messages :foo and :bar with any or no params
>> .. it expects a response to baz with three params
>> .. raises exception if either check fails, or logs, depending on
>> configuraiton

Having a class police the behavior of its instances after they've
already been created strikes me as being at odds with some of the
basic conditions of Ruby runtime -- namely, that objects can change
and aren't constrained by the circumstances of their creation.  I
suspect it would also be likely to discourage duck typing.


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black