module Tins::InstanceExec
Attributes
count[RW]
pool[RW]
Public Instance Methods
instance_exec(*args, &block)
click to toggle source
This is a pure ruby implementation of Ruby 1.9's instance_exec
method. It executes block in the context of this object while parsing *args into the block.
# File lib/tins/dslkit.rb, line 106 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
instance_exec_fetch_symbol()
click to toggle source
Fetch a symbol from a pool in thread save way. If no more symbols are available create a new one, that will be pushed into the pool later.
# File lib/tins/dslkit.rb, line 127 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