Here are two methods defined in the Proc class, designed to be used for functional programming:
def apply(enum) enum.map &self end alias | apply def reduce(enum) enum.inject &self end alias <= reduce Here's an application of them: sum = lambda {|x,y| x+y } mean = (sum<=a)/a.size deviation = lambda {|x| x-mean } square = lambda {|x| x*x } standardDeviation = Math.sqrt((sum<=square|(deviation|a))/(a.size-1)) This excerpt is taken from "The Ruby Programming Language". Here's the thing. In the last line of the above code it uses "sum<=square". That reduce method expects an enumerable as an argument. And instead it is being sent a lambda held in square variable. This should fail because the inject method does not exist on the lambda. It exists on arrays, and other enumerable types. So what am I missing here? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.