def func(a, &closure)
return a if a
closure ||= lambda{ |words| puts "!!! " + words }
closure.call("1")
closure.call("2")
end
func(false){ |words| puts "??? " + words }
In "& close", an ampersand (&) means that the function takes a block as a parameter. What happens is you pass Proc (a block is just Proc defined with a different syntax) to the func function, which is then called using variables 1 and 2.
Value || = means "or equal." It is used to assign a value to a variable if the current value is zero. This is a shorthand for:
closure = lamda{ |words| puts "!!! " + words } if closure.nil
This blog post explains blocks Procs and lamdas well.