Ruby Blocks, Procs, and Closures: CSE 413 Autumn 2008
Ruby Blocks, Procs, and Closures: CSE 413 Autumn 2008
Bl k
Blocks
Bl k E
Block
Execution
ti
yield
i ld
Output:
p
hello
hello
yield
i ld with
ith arguments
t
Bl k and
Blocks
d Procs
P
M ki Procs
Making
P
P
Proc.new;
l bd
lambdas
p.call(x,y)
P
Procs
vs. Lambdas
L bd
Functional Programming in
Ruby
Ruby is definitely not a functional
programming language, but with blocks,
procs, and lambdas, you can do most
anything you could in a functional
lang age
language
For a good discussion, see ch. 6 in The
Ruby Programming Language by
Flanagan and Matsumoto