Class: Proc

Inherits:
Object show all
Defined in:
lib/rui/factory.rb,
lib/rui/observer_utils.rb

Overview

Copyright © 2009 Paolo Capriotti <[email protected]>

This program 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 2 of the License, or (at your option) any later version.

Instance Method Summary collapse

Instance Method Details

#bind(object) ⇒ Object

Bind this Proc to an object.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rui/factory.rb', line 12

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

#generic_call(args) ⇒ Object



142
143
144
145
146
147
148
149
150
151
# File 'lib/rui/observer_utils.rb', line 142

def generic_call(args)
  case arity
  when 0
    call
  when 1
    call(args)
  else
    call(*args)
  end
end