On Sep 26, 2004, at 11:54 AM, Markus wrote:

> On Sun, 2004-09-26 at 11:05, Brian Candler wrote:
>
>> Regarding Associations though: if Hash#each did start returning 
>> these, you
>> would clearly not be able to do
>>
>>     myhash.each { |k,v| ... }
>>
>> any more. So you'd probably want a new interator for that case:
>>
>>     myhash.each_pair { |k,v| ... }          # already exists
>> or
>>     myhash.each_with_index { |v,k| ... }    # like an array
>
>      Perhaps.  I keep feeling that there is an "Ah ha!" lurking in here
> somewhere--if we just look at things on the right way, we could (for
> 2.0) get nearly full backward compatibility, cleaner semantics, and
> nice route for expanded expressiveness.  I'll post more if the idea
> still seems reasonable after I think on it for a day or so...

If Association is a subclass of Array or Values, then it should be 
possible to splat it. Here's an extremely bare-bones version 
demonstrating the possible behavior:

class Association < Values
   def initialize(key, value)
     self.replace [key, value]
   end
   # a simple formatter for inspections, prints "key => value"
   def inspect
     map{|item| item.inspect}.join " => "
   end
end
     ==>nil

# Examples:

h.each{|assoc| p assoc} # inspects the associations
:b => 2
:c => 3
:a => 1
     ==>{:b=>2, :c=>3, :a=>1}
h.each{|(key,val)| puts "key = #{key}, value = #{val}"} # list should 
expand
key = b, value = 2
key = c, value = 3
key = a, value = 1
     ==>{:b=>2, :c=>3, :a=>1}

Note that currently, you don't even have to write |(key,val)|, it will 
auto-expand. But I don't think that's future-proof.

It's a neat idea, but I would wonder how practical it would be; I get 
the feeling our nice fast hash lookups would be ruined... But since I 
don't know the internals...

cheers,
Mark

>
>     -- Markus
>
>