Lambdas and Pops - Jan Hettich

130

Lambdas and Pops - Jan Hettich

Las Vegas Ruby Group

June 18, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

6 slides
  1. Two kinds of Proc “plain old proc” lambda closure? yes

    yes class Proc Proc .lambda? false true semantics yield invocation similar to block method
  2. Creation • “Plain old procs” • Kernel.proc {|args| code} •

    Proc.new {|args| code} • Lambdas • Kernel.lambda {|args| code} • literal: ->(args) {code} • Method.to_proc
  3. call syntax • direct call – foo.call(args) – foo[args] –

    foo.(args) • block-style call – iterator args, &foo
  4. 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”
  5. Let's look at some code • A Digression on Method

    • Argument Passing • return statement • Using next • New behavior in Ruby 2.1.0