Hi,
Thanks for the help with my question. All three solutions are great.
Sorry I wasn't more clear describing the problem. I'll try to be more clear when I ask another question in the future.
I have to admit that I don't think I understand the method below. I tried it out and see that it works, but don't necessarily see how it works yet. I will look at it some more.
Thanks again,
Glenn
···
----- Original Message ----
From: William James <w_a_x_man@yahoo.com>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Sent: Sunday, September 14, 2008 4:02:54 PM
Subject: Re: Passing a method call into a method
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