Use a function as a block
suggest changeMany 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]
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents