Module: DSLKit::InstanceExec

Included in:
Interpreter, Object
Defined in:
lib/dslkit/polite.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.countObject

Returns the value of attribute count.



148
149
150
# File 'lib/dslkit/polite.rb', line 148

def count
  @count
end

.poolObject

Returns the value of attribute pool.



147
148
149
# File 'lib/dslkit/polite.rb', line 147

def pool
  @pool
end

Instance Method Details

#instance_exec(*args, &block) ⇒ Object

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.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/dslkit/polite.rb', line 156

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