[1, 2, 3].map { |i| i + 1 }
[i + 1 for i in [1, 2, 3]]
def plus(i):
return i + 1
map(plus, [1, 2, 3])
map(lambda i: i + 1, [1, 2, 3]) def f(&block)
block.class
end
f { } # => Proc
f(&-> { }) # => Proc
f(&lambda { }) # => Proc
f(&:something) # => Proc
lambda { }.class # => Proc (I think you get the idea)
method(:f).class # => Method
lambda { |i| i + 1 }.call(10) # => 11
you don't typically return in a block, there is implicit return. you would do "next" or "break" depending on what you want to achieve. as far as I know that's the main difference between procs and methods.(not that anybody would do what I do, most people just use blocks, some people use yield, few people use the &block argument, but that's exactly the same)