On Aug 27, 1:04=A0am, Yukihiro Matsumoto <m... / ruby-lang.org> wrote:

> Unlike Smalltalk's Dictionaries, Hashes in Ruby does not provide the
> illusion of being sequence of association. =A0So the proposed new method
> makes less sense in Ruby.

Well, there is some correlation. Ruby even indicates it:

  {:a=3D>1, :b=3D>2, :c=3D>3}.to_a

> Besides that, Associative Arrays (which has normal array methods) and
> hashes cannot behave polymorphic.

I don't think it is about creating an illusion. One doesn't need
perfect polymorphism to be useful. Plus it can be useful in and of
itself --at minimal if you're given an associative array and you want
to make a hash out of it:

  a.inject({}){|h,e|h<<e}

But more abstractly it is polymorphism that allow Mixins to work at
all. Now I recall what it was in that old thread that made me thing it
was a good idea:

  h =3D {:a=3D>1, :b=3D>2, :c=3D>3}

  p h.map{ |e| e }

  #=3D> [[:a, 1], [:b, 2], [:c, 3]]

  class Hash
    def <<(a)
      self[a[0]] =3D a[1]
    end
  end

  module Enumerable

    def map(&block)
      o =3D self.class.new
      each do |e|
        o << yield(e)
      end
      o
    end

  end

  p h.map{ |e| e }

  #=3D> {:a=3D>1, :b=3D>2, :c=3D>3}

That's seems very compelling to me.  Currently using #map on a hash is
of very little use, precisely because b/c it creates an associative
array.

T.