Sha256: 0b4a2c3c003779386f881a4ca27ea308da9352984c2faafa795ce348d6473bdd

Contents?: true

Size: 620 Bytes

Versions: 16

Compression:

Stored size: 620 Bytes

Contents

class Proc
  def bind(object)
    block = self
    object.class_eval do
      method_name = :__proc_rebound_method__
      method = nil
      Thread.exclusive do
        method_already_exists =
          object.respond_to?(method_name) &&
          instance_method(method_name).owner == self

        old_method = instance_method(method_name) if method_already_exists

        define_method(method_name, &block)
        method = instance_method(method_name)
        remove_method(method_name)

        define_method(method_name, old_method) if method_already_exists
      end
      method
    end.bind(object)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
auto_error-0.0.18 lib/core_ext/proc_ext.rb
auto_error-0.0.16 lib/core_ext/proc_ext.rb
auto_error-0.0.15 lib/core_ext/proc_ext.rb
auto_error-0.0.14 lib/core_ext/proc_ext.rb
auto_error-0.0.13 lib/core_ext/proc_ext.rb
auto_error-0.0.12 lib/core_ext/proc_ext.rb
auto_error-0.0.10 lib/core_ext/proc_ext.rb
auto_error-0.0.9 lib/core_ext/proc_ext.rb
auto_error-0.0.8 lib/core_ext/proc_ext.rb
auto_error-0.0.7 lib/core_ext/proc_ext.rb
auto_error-0.0.6 lib/core_ext/proc_ext.rb
auto_error-0.0.5 lib/core_ext/proc_ext.rb
auto_error-0.0.4 lib/core_ext/proc_ext.rb
auto_error-0.0.3 lib/core_ext/proc_ext.rb
auto_error-0.0.2 lib/core_ext/proc_ext.rb
auto_error-0.0.1 lib/core_ext/proc_ext.rb