module DSLKit::InstanceExec
def instance_exec(*args, &block)
executes _block_ in the context of this object while parsing *args into
This is a pure ruby implementation of Ruby 1.9's instance_exec method. It
def instance_exec(*args, &block) instance = self id = instance_exec_fetch_symbol InstanceExec.module_eval do begin define_method id, block instance.__send__ id, *args ensure remove_method id if method_defined?(id) end end ensure InstanceExec.pool << id end
def instance_exec_fetch_symbol
Fetch a symbol from a pool in thread save way. If no more symbols are
def instance_exec_fetch_symbol @@mutex.synchronize do if InstanceExec.pool.empty? InstanceExec.count += 1 symbol = :"__instance_exec_#{InstanceExec.count}__" else symbol = InstanceExec.pool.shift end return symbol end end