Use a function as a block

suggest change

Many functions in Ruby accept a block as an argument. E.g.:

[0, 1, 2].map {|i| i + 1}
 => [1, 2, 3]

If you already have a function that does what you want, you can turn it into a block using &method(:fn):

def inc(num)
   num + 1
end

[0, 1, 2].map &method(:inc)
 => [1, 2, 3]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents