From: Joshua Ballanco Date: 2008-09-15T09:04:16+09:00 Subject: Re: Passing a method call into a method Glenn wrote: > 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 > > def indexes_of > self.empty? ? 'The array is empty.' : hash_of_indexes[self.min] > end > end Use send, as in: class Array def indexes_of(function) self.empty? ? 'The array is empty.' : hash_of_indexes[self.send(function)] end end puts [1, -100, -200.0, 1000000000000.12, 3, 1, -100, -100, -200].indexes_of(:min) -- Posted via http://www.ruby-forum.com/.