Blocks, procs && lambdas
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Blocks, procs && lambdas

  • 328 views
Uploaded on

Small presentation about blocks, procs & lambdas in Ruby programming language

Small presentation about blocks, procs & lambdas in Ruby programming language

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
328
On Slideshare
323
From Embeds
5
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 5

https://twitter.com 5

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Blocks, procs &&lambdas#16 ruby workshop, 2013-03-24Vidmantas Kabošis
  • 2. Closure (CS)● function or reference to a function togetherwith a referencing environment● closure <..> allows a function to accessthose non-local variables even when invokedoutside of its immediate lexical scope [1]1 - http://en.wikipedia.org/wiki/Closure_%28computer_science%29
  • 3. Closures in Ruby1. Block2. Proc3. proc4. lambda
  • 4. Blocks● NOT an object (mind=blown)● Implicit pass/call● Explicit pass/call*● Speed! Explicit invoke is considerably slower(~50%)*● Implicit block within implicit block?● Implicit block behaves like Proc*
  • 5. Proc● Pretty usual method object● Call● Pass any number of argument(s)● respond_to(:arity)● Flow control keywords (return, break, redo,retry, ...)
  • 6. proc● Ruby 1.8: proc == lambda● Ruby 1.9 and up: proc == Proc○ lambda?
  • 7. lambda● Count of arguments● return == break (proc)● ->
  • 8. end● Implicit blocks are not objects, but canbecome an object when referenced(explicitly)● Proc.new == proc, dont care about args toomuch & returns● lambda counts args & diminutive returns
  • 9. end!