Sha256: 6235939bf286466bc39e1f2062e0f82c2fe29534bb5098bb0e0144df94f14417

Contents?: true

Size: 879 Bytes

Versions: 12

Compression:

Stored size: 879 Bytes

Contents

class Object
  # From active_support 2.3.4
  unless defined? instance_exec # 1.9
    module InstanceExecMethods #:nodoc:
    end
    include InstanceExecMethods

    # Evaluate the block with the given arguments within the context of
    # this object, so self is set to the method receiver.
    #
    # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
    def instance_exec(*args, &block)
      begin
        old_critical, Thread.critical = Thread.critical, true
        n = 0
        n += 1 while respond_to?(method_name = "__instance_exec#{n}")
        InstanceExecMethods.module_eval { define_method(method_name, &block) }
      ensure
        Thread.critical = old_critical
      end

      begin
        send(method_name, *args)
      ensure
        InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
quickl-0.4.3 lib/quickl/ext/object.rb
quickl-0.4.2 lib/quickl/ext/object.rb
quickl-0.4.1 lib/quickl/ext/object.rb
quickl-0.4.0 lib/quickl/ext/object.rb
quickl-0.3.0 lib/quickl/ext/object.rb
quickl-0.2.2 lib/quickl/ext/object.rb
quickl-0.2.1 lib/quickl/ext/object.rb
waw-0.3.1 lib/waw/ext/core/object.rb
waw-0.3.0 lib/waw/ext/core/object.rb
quickl-0.2.0 lib/quickl/ext/object.rb
quickl-0.1.1 lib/quickl/ext/object.rb
waw-0.2.2 lib/waw/ext/core/object.rb