Class: Proc
Overview
–
#
A component of ruby-nuggets, some extensions to the Ruby programming # language. #
#
Copyright © 2007-2008 Jens Wille #
#
Authors: #
Jens Wille <jens.wille@uni-koeln.de> #
#
ruby-nuggets is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. #
#
ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. #
#
You should have received a copy of the GNU General Public License along # with ruby-nuggets. If not, see <www.gnu.org/licenses/>. #
#
++
Instance Method Summary collapse
-
#bind(object) ⇒ Object
call-seq: proc.bind(object) => aMethod.
Instance Method Details
#bind(object) ⇒ Object
call-seq:
proc.bind(object) => aMethod
Straight from Rails’ ActiveSupport – effectively binds proc to object.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nuggets/proc/bind.rb', line 34 def bind(object) block, time = self, Time.now (class << object; self; end).class_eval { method_name = "__bind_#{time.to_i}_#{time.usec}" define_method(method_name, &block) method = instance_method(method_name) remove_method(method_name) method }.bind(object) end |