Skip to content

Instantly share code, notes, and snippets.

@nusco
Created August 18, 2010 15:10
Show Gist options
  • Save nusco/535058 to your computer and use it in GitHub Desktop.
Save nusco/535058 to your computer and use it in GitHub Desktop.
Spell: Deferred Evaluation
# ==========================
# Spell: Deferred Evaluation
# ==========================
# Store a piece of code and its context in a proc or lambda for evaluation later.
class C
def store(&block)
@my_code_capsule = block
end
def execute
@my_code_capsule.call
end
end
obj = C.new
obj.store { $X = 1 }
$X = 0
obj.execute
$X # => 1
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment