You cannot assign a block to a variable because the block is not really an object as such.
What you can do is assign a Proc object to a variable, and then convert it to a block using the & unary prefix operator:
numbers = 1..10 print numbers.map {|x| x * x } square = -> x { x * x } print numbers.map &square
JΓΆrg W Mittag
source share