Class: Proc

Inherits:
Object show all
Defined in:
lib/multiarray.rb

Overview

Proc#bind is defined if it does not exist already

Instance Method Summary collapse

Instance Method Details

#bind(object) ⇒ Method

Proc#bind is defined if it does not exist already

Parameters:

  • object (Object)

    Object to bind this instance of Proc to.

Returns:

  • (Method)

    The bound method.



56
57
58
59
60
61
62
63
64
65
# File 'lib/multiarray.rb', line 56

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