On Sep 14, 8:18 am, Glenn <glenn_r... / yahoo.com> wrote:
> [Note:  parts of this message were removed to make it a legal post.]
>
> Hi,
>
> I am trying to figure out how to pass a method call into a method.
>
> I wrote a generic method that call be called on an array of numbers, and returns an array of the index values in the receiver that meet a specified condition:
>
> class Array
>   def hash_of_indexes
>     if self.empty?
>       'The array is empty.'
>     else
>       h = {}
>       self.each_with_index { |e, i| h.include?(e.to_f) ? h[e.to_f] << i : h[e.to_f] = [i] }
>       h
>     end
>   end


class Array
  def hash_of_indexes
    h = {}
    each_with_index{ |e,i|
      e = e.to_f
      h[e] = Array( h[e] ) << i }
    h
  end
end