Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Lambdas and Pops - Jan Hettich
Las Vegas Ruby Group
June 18, 2014
0
22
Lambdas and Pops - Jan Hettich
Las Vegas Ruby Group
June 18, 2014
Tweet
Share
More Decks by Las Vegas Ruby Group
See All by Las Vegas Ruby Group
lvrug
0
77
lvrug
0
25
lvrug
0
49
lvrug
0
25
lvrug
3
75
lvrug
1
56
lvrug
1
61
lvrug
1
34
lvrug
0
25
Featured
See All Featured
reverentgeek
27
1.9k
geoffreycrofte
18
790
notwaldorf
13
1.6k
shpigford
368
42k
shlominoach
176
7.4k
roundedbygravity
84
7.8k
eileencodes
113
25k
smashingmag
229
18k
moore
125
21k
swwweet
206
6.8k
ufuk
56
5.4k
robhawkes
52
2.8k
Transcript
λ's and POP's Jan Hettich LVRUG 5/21/2014
Two kinds of Proc “plain old proc” lambda closure? yes
yes class Proc Proc .lambda? false true semantics yield invocation similar to block method
Creation • “Plain old procs” • Kernel.proc {|args| code} •
Proc.new {|args| code} • Lambdas • Kernel.lambda {|args| code} • literal: ->(args) {code} • Method.to_proc
call syntax • direct call – foo.call(args) – foo[args] –
foo.(args) • block-style call – iterator args, &foo
call semantics • yield semantics (blocks, pops) • similar to
parallel assignment • return => lexically enclosing method • invocation semantics (methods, lambdas) • number of arguments must match • “diminutive return”
Let's look at some code • A Digression on Method
• Argument Passing • return statement • Using next • New behavior in Ruby 2.1.0