Sha256: 6fc47dbdb64048d16baeab5ee9fee556f9d635cc337491846bd57bba93545315

Contents?: true

Size: 804 Bytes

Versions: 6

Compression:

Stored size: 804 Bytes

Contents

# CHANGE 2006-12-27 trans
# * Deprecated use of TemporaryMethods module

require 'thread'

class Proc

  # Bind a proc to an object. Returns a Method.
  #
  # The block's #to_s method (same as #inspect) is
  # used for the temporary method label defined in
  # the Object class.

  def bind(object=nil)
    object ||= eval("self", self)
    block = self
    store = Object
    begin
      old, Thread.critical = Thread.critical, true
      #n=0; n+=1 while store.method_defined?(name="_bind_#{n}")
      name="_bind_#{block}"
      store.module_eval do
        define_method name, &block
      end
      return object.method(name)
    ensure
      store.module_eval do
        remove_method name #rescue nil
        #undef_method name #rescue nil
      end
      Thread.critical = old
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-1.8.0 lib/facets/core/proc/bind.rb
facets-1.8.20 lib/facets/core/proc/bind.rb
facets-1.8.49 lib/facets/core/proc/bind.rb
facets-1.8.51 lib/facets/core/proc/bind.rb
facets-1.8.54 lib/facets/core/proc/bind.rb
facets-1.8.8 lib/facets/core/proc/bind.rb