Hi --

On Sat, 14 Nov 2009, Bill Kelly wrote:

>
> From: "David Turnbull" <dsturnbull / gmail.com>
>> On 14/11/2009, at 15:21, James Edward Gray II <james / graysoftinc.com> 
>> wrote:
>>> I would like to see us move away from considering classes to be  types at 
>>> all in Ruby.  Who knows what modules an object has mixed  into it and who 
>>> knows what singleton methods are defined on it.  A  class, which is what 
>>> people traditionally take for the type, is just  one piece of an object's 
>>> identity.
>> 
>> I would still look immediately to the class of the object in order to  find 
>> out what it's supposed to do. From there, the class definition  will 
>> probably list it's module inclusions prominently.
>
> A human looking to documentation to find out what an object
> of a partiular class is supposed to *do*, is one thing.  But
> then there's the programmatic flipside where one could code
> a method to select between different behaviors based on the
> class-type of a given argument-object.
>
> def foo(bar)
>   if bar.is_a? Array
>     do_array_thing(bar)
>   elsif bar.is_a? String
>     do_string_thing(bar)
>   else
>     ... # ?
>   end
> end
>
> I believe it's (variations on) the above that are viewed
> as unreasonably restrictive in ruby.
>
> It's challenging, too, because even :respond_to? can be
> misleading.

Indeed:

$ ./script/console 
Loading development environment (Rails 2.3.3)
>> c = Container.first
=> #<Container id: 1, name: "stuff", created_at: "2009-09-14
20:51:19", updated_at: "2009-09-14 20:51:19">
>> items = c.items
=> [#<Item id: 345698075, collection_id: 1, created_at: "2009-09-16
22:29:41", updated_at: "2009-09-16 22:47:27", description: "abc">]
>> items.class
=> Array
>> items.respond_to?(:find)
=> true
>> items.find {|item| item.description == "abc" }
ActiveRecord::RecordNotFound: Couldn't find Item without an ID

Here, it's all about the documented interface, not the class name and
not the method names.


David

-- 
The          Ruby training with D. Black, G. Brown, J.McAnally
Compleat     Jan 22-23, 2010, Tampa, FL
Rubyist      http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)