/ruby-dynamic-binding

Implements a flexible form of dynamic binding to Ruby which allows to run a Proc inside a custom name lookup context

Primary LanguageRubyMIT LicenseMIT

Dynamic Binding for Ruby Procs

All based on this

wercker status

How to use

require 'contextual_proc'

def doubler
  ContextualProc.new { number*2 }
end

# In a completely different context
number = 4
doubler.apply(binding)
# => 8

The example above is an over-simplifed anti-pattern but it demonstrates the principle - a block suddenly gains access to the binding from which it is called