Sha256: 671ce9b63e4fd879073e606fdafd0bfbfa1bd5a55d1abb69356034d7ac2409b4

Contents?: true

Size: 605 Bytes

Versions: 10

Compression:

Stored size: 605 Bytes

Contents

class Proc

  # Bind a Proc to an object returning a Method.
  #
  # NOTE: This version comes from Rails. The old Facets
  #       version used thread.rb, but I no longer think
  #       the implementaiton is thread critical. Please
  #       make a bug report if this proves wrong.
  #
  def bind(object)
    block, time = self, Time.now
    (class << object; self; end).class_eval do
      method_name = "__bind_#{time.to_i}_#{time.usec}"
      define_method(method_name, &block)
      method = instance_method(method_name)
      remove_method(method_name)
      method
    end.bind(object)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/proc/bind.rb
facets-2.8.3 lib/core/facets/proc/bind.rb
facets-2.8.2 lib/core/facets/proc/bind.rb
facets-2.8.1 lib/core/facets/proc/bind.rb
facets-2.8.0 lib/core/facets/proc/bind.rb
facets-2.7.0 lib/core/facets/proc/bind.rb
facets-2.6.0 lib/core/facets/proc/bind.rb
facets-2.5.0 lib/core/facets/proc/bind.rb
facets-2.5.1 lib/core/facets/proc/bind.rb
facets-2.5.2 lib/core/facets/proc/bind.rb