On 10/29/06, Robert Klemme <shortcutter / googlemail.com> wrote:
> Logan Capaldo wrote:
> > Alternative decandence:
> >
> > class Array
> >   def to_hsh
> >     require 'enumerator'
> >     to_enum(:each_slice, 2).to_a.inject({}) { |h, (k, v)| h.update(k=>v) }
> >   end
> > end
>
> This seems a bit inefficient.  If you write a method then I'd prefer
>
> require 'enumerator'
> module Enumerable
>    def to_hash
>      h = {}
>      to_enum(:each_slice, 2).each {|k,v| h[k]=v}
>      h
>    end
> end

Never thought I'd see you speak out *against* inject :)

martin