From: Christian Neukirchen Date: 2005-07-31T20:00:19+09:00 Subject: Re: Higher Order Functions "Dave Burt" writes: > The problem here is that f(element) means call the method self.f (which > doesn't exist, hence the error), whereas you want to call the "function" > represented by the parameter f. > > You can do this a couple of ways. Charles suggested you pass f as a Method > to every: >> p Functional.every(method(:times_two), [1,2,3] >> And in Functional, it would be lst.collect { |element| f.call(element) >> } > > f.call will also work if f is a Proc, so you could also do: > Functional.every(proc{|x| x * 2}, [1, 2, 3]) > > You can pass a symbol, but I wouldn't recommend it - make the caller pass a > callable object (a Proc or Method). IMO, you should pass a block. Then, you still can call it like that: Functional.every [1,2,3], &method(:foo) > Dave -- Christian Neukirchen http://chneukirchen.org