Sha256: fb714da4e4e36b0b751881b67ef85492fce509d4f629591606d6e0ba4de74b66

Contents?: true

Size: 776 Bytes

Versions: 13

Compression:

Stored size: 776 Bytes

Contents

# instance_exec comes with >1.8.7 thankfully
if VERSION <= '1.8.6'
  class Object
    module InstanceExecHelper; end
    include InstanceExecHelper
    # instance_exec method evaluates a block of code relative to the specified object, with parameters whom come from outside the object.
    def instance_exec(*args, &block)
      begin
        old_critical, Thread.critical = Thread.critical, true
        n = 0
        n += 1 while respond_to?(mname="__instance_exec#{n}")
        InstanceExecHelper.module_eval{ define_method(mname, &block) }
      ensure
        Thread.critical = old_critical
      end
      begin
        ret = send(mname, *args)
      ensure
        InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
      end
      ret
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
bret-watircraft-0.4.0 lib/extensions/object.rb
bret-watircraft-0.4.1 lib/extensions/object.rb
bret-watircraft-0.4.2 lib/extensions/object.rb
bret-watircraft-0.4.3 lib/extensions/object.rb
bret-watircraft-0.4.4 lib/extensions/object.rb
bret-watircraft-0.4.5 lib/extensions/object.rb
bret-watircraft-0.5.0 lib/extensions/object.rb
scudco-taza-0.8.1 lib/extensions/object.rb
scudco-taza-0.8.3 lib/extensions/object.rb
scudco-taza-0.8.4 lib/extensions/object.rb
taza-0.8.2 lib/extensions/object.rb
taza-0.8.3 lib/extensions/object.rb
taza-0.8.4 lib/extensions/object.rb