module Cordon::MethodList
Public Instance Methods
includes?(subject, method)
click to toggle source
# File lib/cordon/method_list.rb, line 3 def includes?(subject, method) method_list.has_key?([subject, method]) end
invoke_method(instance, subject, method, *args, &b)
click to toggle source
# File lib/cordon/method_list.rb, line 22 def invoke_method(instance, subject, method, *args, &b) unbound_method = method_list[[subject, method]] unbound_method.bind(instance).call(*args, &b) end
wrap_method(subject, method)
click to toggle source
# File lib/cordon/method_list.rb, line 13 def wrap_method(subject, method) return if includes?(subject, method) # be idempotent # Unbind the original method, and replace it with a wrapper that # decides whether to bind and call the original unbind_method(subject, method) subject.__cordon__wrap_method__(method) end
wrap_methods(subject, methods)
click to toggle source
# File lib/cordon/method_list.rb, line 7 def wrap_methods(subject, methods) methods.each do |method| wrap_method(subject, method.to_sym) end end
Protected Instance Methods
method_list()
click to toggle source
# File lib/cordon/method_list.rb, line 34 def method_list @method_list ||= {} end
unbind_method(subject, method)
click to toggle source
# File lib/cordon/method_list.rb, line 29 def unbind_method(subject, method) unbound_method = subject.instance_method(method) # will raise NameError if the method doesn't exist method_list[[subject, method]] = unbound_method end