Hi,

At Tue, 25 Oct 2005 12:10:18 +0900,
Shannon Fang wrote in [ruby-talk:162399]:
> Abstract
> 
> A simple method that construct a hash from an array. Just like Hash#to_a 
> return an array from hash.

Agreed here, but

> Proposal
> 
> Add a method to_h (not to_hash) in the Array class, so that user can:
> 
> a = [1, 2, 3, 4, 5]
> p a.to_h { |i, v| v * 2}  --> {5=>10, 1=>2, 2=>4, 3=>6, 4=>8}
> p a.to_h(3)                 --> {5=>3, 1=>3, 2=>3, 3=>3, 4=>3}

I expect that method as:

  h = {"foo"=>1,"bar"=>2}
  a = h.to_a			# => [["foo", 1], ["bar", 2]]
  a.to_h			# => {"foo"=>1,"bar"=>2} == h

  module Enumerable
    def to_h
      hash = {}
      each {|key, value| hash[key] = value}
      hash
    end
  end

-- 
Nobu Nakada