SlideShare a Scribd company logo
1 of 20
Download to read offline
Blocks



2011   8   25
Outline

                • Basics	
  of	
  blocks
                • Scopes,	
  carry	
  variables	
  through	
  scopes
                • Manipulate	
  scopes	
  	
  using	
  instance_eval(	
  )
                • Convert	
  blocks	
  to	
  callable	
  objects
                • A	
  DSL	
  example

2011   8   25
Definition
                • Definition of blocks
                    • Multi-lines
                          do ... end
                     • Single line
                          Curly braces {}



2011   8   25
Features
                def a_method(a, b)
                  a + yield(a, b)
                end

                a_method(1,2){|x,y|(x+y)*3} #=>10



                • Defined when calling a method
                • Block is passed to method
                • Method can call block using yield
                • Blocks can have arguments
                • Block can return values
2011   8   25
Using C#->Ruby
                 module Kernel
                   def using(resource)
                       begin
                         yield
                       ensure    # Ensure the dispose to be called
                         resource.dispose
                       end
                   end
                 end




                The exception of block called by ‘yield’ can be
                always captured by ‘ensure’

2011   8   25
Closures
                Bindings: Local variables, instance variables, self

                  def my_method
                   x = "Goodbye"
                   yield("cruel" )
                  end
                  x = "Hello"
                  my_method {|y| "#{x}, #{y} world" }
                  # => ?




2011   8   25
Using
                 def my_method
                   x = "Goodbye"
                   yield("cruel" )
                 end
                 x = "Hello"
                 my_method {|y| "#{x}, #{y} world" }
                 # => "Hello, cruel world"




                Block definition -> find x variables -> take x to
                method

2011   8   25
Block local variables
                def my_method
                yield
                end
                top_level_variable = 1
                my_method do
                 top_level_variable += 1
                 local_to_block = 1
                end


                top_level_variable # => ?
                local_to_block	 # => ?




2011   8   25
Block local variables
                def my_method
                yield
                end
                top_level_variable = 1
                my_method do
                 top_level_variable += 1
                 local_to_block = 1
                end


                top_level_variable # => 2
                local_to_block	 # => Error!




2011   8   25
Scope gates
                v1 = 1
                class MyClass
                 v2 = 2
                 local_variables
                  def my_method
                      v3 = 3
                      local_variables
                 end
                  local_variables
                end
                obj = MyClass.new
                obj.my_method
                obj.my_method
                local_variables


2011   8   25
Scope gates
                v1 = 1
                class MyClass    # SCOPE GATE: entering class
                 v2 = 2          # => ["v2"]
                 local_variables
                  def my_method # SCOPE GATE: entering def
                      v3 = 3
                      local_variables
                 end              # SCOPE GATE: leaving def
                  local_variables       # => ["v2"]
                end              # SCOPE GATE: leaving class
                obj = MyClass.new
                obj.my_method # => [:v3]
                obj.my_method # => [:v3]
                local_variables # => [:v1, :obj]


2011   8   25
Beyond scopes
                •   Global variables
                    • $var
                •   Top-level Instance variables
                    • @var
                • Scope wrap-up
                   • Class.new
                   • Module.new
                   • define_methods
2011   8   25
Example
                my_var = "Success"
                MyClass = Class.new do
                  puts "#{my_var} in the class definition!"
                  define_method :my_method do
                      puts "#{my_var} in the method!"
                  end
                end
                MyClass.new.my_method
                # => Success in the class definition!
                # => Success in the method!




2011   8   25
Instance_eval()
                class MyClass
                def initialize
                  @v = 1
                 end
                end
                obj = MyClass.new
                obj.instance_eval do
                 self   	 # => #<MyClass:0x3340dc @v=1>
                 @v	       # => 1
                end
                v=2
                obj.instance_eval { @v = v }
                obj.instance_eval { @v } # => 2 (passed to the block)



2011   8   25
Instance_eval()
                class CleanRoom
                def complex_calculation
                      # ...
                 end
                 def do_something
                      # ...
                 end
                end
                clean_room = CleanRoom.new
                 clean_room.instance_eval do
                      if complex_calculation > 10 do_something
                 end
                end



2011   8   25
Callable objects
                Call blocks by change it to object using proc or lambda,
                A Proc is a block that has been turned into an object.

                Proc:
                inc = Proc.new {|x| x + 1 }
                inc.call(2) # => 3

                Lambda:
                dec = lambda {|x| x - 1 }
                dec.class # => Proc
                dec.call(2) # => 1




2011   8   25
Procs VS Lambdas
                • Procs created with lambda( ) -> lambdas
                • Return
                   • return in lambda is more like method,
                     while return in procs return from scope
                     (defined in the scope)
                • Arity
                   • lambdas failed with wrong arguments but
                     proc is ok

2011   8   25
methods
                class MyClass
                  def initialize(value)
                    @x = value
                  end
                  def my_method
                    @x
                  end
                end
                object = MyClass.new(1)
                m = object.method :my_method
                m.call

                a lambda is evaluated in the scope
                Method is evaluated in the scope of its object




2011   8   25
Callable object wrap-up
                Blocks: Evaluated in the scope in which they’re defined.

                Procs: Objects of class Proc. Like blocks, they are
                evaluated in the scope where they’re defined.

                Lambdas: Also objects of class Proc but subtly different
                from regular proc.

                Methods: Bound to an object, they are evaluated in that
                object’s scope. They can also be unbound from their
                scope and rebound to the scope of another object.




2011   8   25
DSL

                • DSL for individual event
                • Shared among events
                • Adding setup instruction
                • Using & operator to pass setup
                • Not using global variables

2011   8   25

More Related Content

What's hot

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 

What's hot (20)

Alexander Makarov "Let’s talk about code"
Alexander Makarov "Let’s talk about code"Alexander Makarov "Let’s talk about code"
Alexander Makarov "Let’s talk about code"
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Delegate
DelegateDelegate
Delegate
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Dart
DartDart
Dart
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
Inheritance
InheritanceInheritance
Inheritance
 
Class and object
Class and objectClass and object
Class and object
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 

Similar to block

Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
ConFoo
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
Nando Vieira
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testing
Peter Edwards
 
System Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancementsSystem Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancements
Subash John
 

Similar to block (20)

Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Why I choosed Ruby
Why I choosed RubyWhy I choosed Ruby
Why I choosed Ruby
 
Ruby Blocks
Ruby BlocksRuby Blocks
Ruby Blocks
 
Model Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in ScalaModel Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in Scala
 
Metaprogramming code-that-writes-code
Metaprogramming code-that-writes-codeMetaprogramming code-that-writes-code
Metaprogramming code-that-writes-code
 
Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)Removing Methods (MOTM 2010.01)
Removing Methods (MOTM 2010.01)
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
Introduction to ruby eval
Introduction to ruby evalIntroduction to ruby eval
Introduction to ruby eval
 
Real world cross-platform testing
Real world cross-platform testingReal world cross-platform testing
Real world cross-platform testing
 
From dot net_to_rails
From dot net_to_railsFrom dot net_to_rails
From dot net_to_rails
 
System Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancementsSystem Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancements
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
 
Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Rails3ハンズオン資料
Rails3ハンズオン資料Rails3ハンズオン資料
Rails3ハンズオン資料
 

Recently uploaded

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
lizamodels9
 

Recently uploaded (20)

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 

block

  • 1. Blocks 2011 8 25
  • 2. Outline • Basics  of  blocks • Scopes,  carry  variables  through  scopes • Manipulate  scopes    using  instance_eval(  ) • Convert  blocks  to  callable  objects • A  DSL  example 2011 8 25
  • 3. Definition • Definition of blocks • Multi-lines do ... end • Single line Curly braces {} 2011 8 25
  • 4. Features def a_method(a, b) a + yield(a, b) end a_method(1,2){|x,y|(x+y)*3} #=>10 • Defined when calling a method • Block is passed to method • Method can call block using yield • Blocks can have arguments • Block can return values 2011 8 25
  • 5. Using C#->Ruby module Kernel def using(resource) begin yield ensure # Ensure the dispose to be called resource.dispose end end end The exception of block called by ‘yield’ can be always captured by ‘ensure’ 2011 8 25
  • 6. Closures Bindings: Local variables, instance variables, self def my_method x = "Goodbye" yield("cruel" ) end x = "Hello" my_method {|y| "#{x}, #{y} world" } # => ? 2011 8 25
  • 7. Using def my_method x = "Goodbye" yield("cruel" ) end x = "Hello" my_method {|y| "#{x}, #{y} world" } # => "Hello, cruel world" Block definition -> find x variables -> take x to method 2011 8 25
  • 8. Block local variables def my_method yield end top_level_variable = 1 my_method do top_level_variable += 1 local_to_block = 1 end top_level_variable # => ? local_to_block # => ? 2011 8 25
  • 9. Block local variables def my_method yield end top_level_variable = 1 my_method do top_level_variable += 1 local_to_block = 1 end top_level_variable # => 2 local_to_block # => Error! 2011 8 25
  • 10. Scope gates v1 = 1 class MyClass v2 = 2 local_variables def my_method v3 = 3 local_variables end local_variables end obj = MyClass.new obj.my_method obj.my_method local_variables 2011 8 25
  • 11. Scope gates v1 = 1 class MyClass # SCOPE GATE: entering class v2 = 2 # => ["v2"] local_variables def my_method # SCOPE GATE: entering def v3 = 3 local_variables end # SCOPE GATE: leaving def local_variables # => ["v2"] end # SCOPE GATE: leaving class obj = MyClass.new obj.my_method # => [:v3] obj.my_method # => [:v3] local_variables # => [:v1, :obj] 2011 8 25
  • 12. Beyond scopes • Global variables • $var • Top-level Instance variables • @var • Scope wrap-up • Class.new • Module.new • define_methods 2011 8 25
  • 13. Example my_var = "Success" MyClass = Class.new do puts "#{my_var} in the class definition!" define_method :my_method do puts "#{my_var} in the method!" end end MyClass.new.my_method # => Success in the class definition! # => Success in the method! 2011 8 25
  • 14. Instance_eval() class MyClass def initialize @v = 1 end end obj = MyClass.new obj.instance_eval do self # => #<MyClass:0x3340dc @v=1> @v # => 1 end v=2 obj.instance_eval { @v = v } obj.instance_eval { @v } # => 2 (passed to the block) 2011 8 25
  • 15. Instance_eval() class CleanRoom def complex_calculation # ... end def do_something # ... end end clean_room = CleanRoom.new clean_room.instance_eval do if complex_calculation > 10 do_something end end 2011 8 25
  • 16. Callable objects Call blocks by change it to object using proc or lambda, A Proc is a block that has been turned into an object. Proc: inc = Proc.new {|x| x + 1 } inc.call(2) # => 3 Lambda: dec = lambda {|x| x - 1 } dec.class # => Proc dec.call(2) # => 1 2011 8 25
  • 17. Procs VS Lambdas • Procs created with lambda( ) -> lambdas • Return • return in lambda is more like method, while return in procs return from scope (defined in the scope) • Arity • lambdas failed with wrong arguments but proc is ok 2011 8 25
  • 18. methods class MyClass def initialize(value) @x = value end def my_method @x end end object = MyClass.new(1) m = object.method :my_method m.call a lambda is evaluated in the scope Method is evaluated in the scope of its object 2011 8 25
  • 19. Callable object wrap-up Blocks: Evaluated in the scope in which they’re defined. Procs: Objects of class Proc. Like blocks, they are evaluated in the scope where they’re defined. Lambdas: Also objects of class Proc but subtly different from regular proc. Methods: Bound to an object, they are evaluated in that object’s scope. They can also be unbound from their scope and rebound to the scope of another object. 2011 8 25
  • 20. DSL • DSL for individual event • Shared among events • Adding setup instruction • Using & operator to pass setup • Not using global variables 2011 8 25