SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
Blocks, procs &&
lambdas
#16 ruby workshop, 2013-03-24
Vidmantas Kabošis
Closure (CS)
● function or reference to a function together
with a referencing environment
● closure <..> allows a function to access
those non-local variables even when invoked
outside of its immediate lexical scope [1]
1 - http://en.wikipedia.org/wiki/Closure_%28computer_science%29
Closures in Ruby
1. Block
2. Proc
3. proc
4. lambda
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*
Proc
● Pretty usual method object
● Call
● Pass any number of argument(s)
● respond_to(:arity)
● Flow control keywords (return, break, redo,
retry, ...)
proc
● Ruby 1.8: proc == lambda
● Ruby 1.9 and up: proc == Proc
○ lambda?
lambda
● Count of arguments
● return == break (proc)
● ->
end
● Implicit blocks are not objects, but can
become an object when referenced
(explicitly)
● Proc.new == proc, don't care about args too
much & returns
● lambda counts args & diminutive returns
end!

Contenu connexe

Tendances

Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overviewSergey Stupin
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)Laurence Chen
 
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMCDiagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMCMushfekur Rahman
 
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaBuilding a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaMushfekur Rahman
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Codemotion
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.jsRuben Tan
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingLubomir Rintel
 
TANET 2018 - Insights into the reliability of open-source distributed file sy...
TANET 2018 - Insights into the reliability of open-source distributed file sy...TANET 2018 - Insights into the reliability of open-source distributed file sy...
TANET 2018 - Insights into the reliability of open-source distributed file sy...Hua Chu
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQLuke Luo
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using JavaRahul Hada
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQpieterh
 
PostgreSQL: present and near future
PostgreSQL: present and near futurePostgreSQL: present and near future
PostgreSQL: present and near futureNaN-tic
 
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...DevDay.org
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....AboutYouGmbH
 

Tendances (20)

Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overview
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMCDiagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
 
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaBuilding a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
 
Wireshark lecture
Wireshark lectureWireshark lecture
Wireshark lecture
 
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017Briefly Rust - Daniele Esposti - Codemotion Rome 2017
Briefly Rust - Daniele Esposti - Codemotion Rome 2017
 
Leveraging zeromq for node.js
Leveraging zeromq for node.jsLeveraging zeromq for node.js
Leveraging zeromq for node.js
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
TANET 2018 - Insights into the reliability of open-source distributed file sy...
TANET 2018 - Insights into the reliability of open-source distributed file sy...TANET 2018 - Insights into the reliability of open-source distributed file sy...
TANET 2018 - Insights into the reliability of open-source distributed file sy...
 
Event Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQEvent Driven with LibUV and ZeroMQ
Event Driven with LibUV and ZeroMQ
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using Java
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQ
 
Reflection
ReflectionReflection
Reflection
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Polymorphism in c++
Polymorphism in c++Polymorphism in c++
Polymorphism in c++
 
PostgreSQL: present and near future
PostgreSQL: present and near futurePostgreSQL: present and near future
PostgreSQL: present and near future
 
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
[DevDay 2019] Reactive Programming with JavaScript - By Pham Nguyen Duc, Web ...
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
 

Similaire à Blocks, procs && lambdas

My Sql Proxy
My Sql ProxyMy Sql Proxy
My Sql ProxyLiu Lizhi
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overviewjessesanford
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...sangam biradar
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....Sadia Textile
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures CodingMax Kleiner
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features Florian Hopf
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a gamejackpot201
 
CS 626 - March : Capsicum: Practical Capabilities for UNIX
CS 626 - March : Capsicum: Practical Capabilities for UNIXCS 626 - March : Capsicum: Practical Capabilities for UNIX
CS 626 - March : Capsicum: Practical Capabilities for UNIXruchith
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGlobalLogic Ukraine
 
A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16Max Kleiner
 
Cli jbug
Cli jbugCli jbug
Cli jbugmaeste
 
SyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserializationSyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserializationDavid Jorm
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning TalkJames Dennis
 
Other Approaches (Concurrency)
Other Approaches (Concurrency)Other Approaches (Concurrency)
Other Approaches (Concurrency)Sri Prasanna
 

Similaire à Blocks, procs && lambdas (20)

My Sql Proxy
My Sql ProxyMy Sql Proxy
My Sql Proxy
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
funcs, func expressions, closure, returning funcs, recursion, the stack -goph...
 
We shall play a game....
We shall play a game....We shall play a game....
We shall play a game....
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
Modern Java Features
Modern Java Features Modern Java Features
Modern Java Features
 
0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri0507 057 01 98 * Adana Klima Servisleri
0507 057 01 98 * Adana Klima Servisleri
 
Shall we play a game
Shall we play a gameShall we play a game
Shall we play a game
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
CS 626 - March : Capsicum: Practical Capabilities for UNIX
CS 626 - March : Capsicum: Practical Capabilities for UNIXCS 626 - March : Capsicum: Practical Capabilities for UNIX
CS 626 - March : Capsicum: Practical Capabilities for UNIX
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
 
A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16
 
Cli jbug
Cli jbugCli jbug
Cli jbug
 
AS7 and CLI
AS7 and CLIAS7 and CLI
AS7 and CLI
 
Fluentd vs. Logstash for OpenStack Log Management
Fluentd vs. Logstash for OpenStack Log ManagementFluentd vs. Logstash for OpenStack Log Management
Fluentd vs. Logstash for OpenStack Log Management
 
SyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserializationSyScan 2016 - Remote code execution via Java native deserialization
SyScan 2016 - Remote code execution via Java native deserialization
 
Nyt Prof 200910
Nyt Prof 200910Nyt Prof 200910
Nyt Prof 200910
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning Talk
 
08 subprograms
08 subprograms08 subprograms
08 subprograms
 
Other Approaches (Concurrency)
Other Approaches (Concurrency)Other Approaches (Concurrency)
Other Approaches (Concurrency)
 

Plus de Vidmantas Kabošis

Plus de Vidmantas Kabošis (13)

One on Ones
One on OnesOne on Ones
One on Ones
 
In Quality We Trust
In Quality We TrustIn Quality We Trust
In Quality We Trust
 
Dangerous Ruby (or: Job Security)
Dangerous Ruby (or: Job Security)Dangerous Ruby (or: Job Security)
Dangerous Ruby (or: Job Security)
 
Freelancing platforms - diff
Freelancing platforms - diffFreelancing platforms - diff
Freelancing platforms - diff
 
Ruby.new @ VilniusRB
Ruby.new @ VilniusRBRuby.new @ VilniusRB
Ruby.new @ VilniusRB
 
10 tėvystės pamokų
10 tėvystės pamokų10 tėvystės pamokų
10 tėvystės pamokų
 
Cucumber @ VilniusPHP
Cucumber @ VilniusPHPCucumber @ VilniusPHP
Cucumber @ VilniusPHP
 
Ruby. Pradžia
Ruby. PradžiaRuby. Pradžia
Ruby. Pradžia
 
Rails Girls Vilnius - lightning talk
Rails Girls Vilnius - lightning talkRails Girls Vilnius - lightning talk
Rails Girls Vilnius - lightning talk
 
Capistrano @ VilniusPHP
Capistrano @ VilniusPHPCapistrano @ VilniusPHP
Capistrano @ VilniusPHP
 
Ruby on rails @ Tobulėtuvė
Ruby on rails @ TobulėtuvėRuby on rails @ Tobulėtuvė
Ruby on rails @ Tobulėtuvė
 
RubyConfLT2012: Legacy / long running projects
RubyConfLT2012: Legacy / long running projectsRubyConfLT2012: Legacy / long running projects
RubyConfLT2012: Legacy / long running projects
 
ERb alternatyvos
ERb alternatyvosERb alternatyvos
ERb alternatyvos
 

Dernier

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Dernier (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Blocks, procs && lambdas

  • 1. Blocks, procs && lambdas #16 ruby workshop, 2013-03-24 Vidmantas Kabošis
  • 2. Closure (CS) ● function or reference to a function together with a referencing environment ● closure <..> allows a function to access those non-local variables even when invoked outside of its immediate lexical scope [1] 1 - http://en.wikipedia.org/wiki/Closure_%28computer_science%29
  • 3. Closures in Ruby 1. Block 2. Proc 3. proc 4. 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 can become an object when referenced (explicitly) ● Proc.new == proc, don't care about args too much & returns ● lambda counts args & diminutive returns