Quote:
Originally Posted by Xhad
Write a named function. The fact that you pass a function value by just using the name of the function as a value was one reason I was so surprised at how complicated it is to treat named functions like values in Ruby.
you basically never need to do this in ruby because you have multiline blocks and lambdas.
Code:
(1..5).map do |x|
x*x
end
the part you are calling really complicated is when you want to use a method as a block. but even if you do want to do that it's actually only one extra word and symbol (which converts the method to a proc):
Code:
def square(x)
x*x
end
p (1..5).map(&method(:square))
it's important to note in the above square is a method on the main object, not a free floating function, which doesn't really exist in ruby.
Last edited by gaming_mouse; 02-11-2014 at 01:55 AM.