Files

DSLKit::InstanceExec

Attributes

pool[RW]

(Not documented)

count[RW]

(Not documented)

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/dslkit/polite.rb, line 152
      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/dslkit/polite.rb, line 173
      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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.