Class/Module Index [+]

Quicksearch

RR::Injections::SingletonMethodAddedInjection

Public Class Methods

create(subject) click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 5
def create(subject)
  instances[subject] ||= begin
    new(subject).bind
  end
end
exists?(subject) click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 11
def exists?(subject)
  instances.include?(subject)
end
new(subject) click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 16
def initialize(subject)
  @subject = subject
  @placeholder_method_defined = false
end

Public Instance Methods

bind() click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 21
def bind
  unless subject.respond_to?(original_method_alias_name)
    unless subject.respond_to?(:singleton_method_added)
      @placeholder_method_defined = true
      subject_class.class_eval do
        def singleton_method_added(method_name)
          super
        end
      end
    end

    memoized_subject = subject
    memoized_original_method_alias_name = original_method_alias_name
    subject_class.__send__(:alias_method, original_method_alias_name, :singleton_method_added)
    subject_class.__send__(:define_method, :singleton_method_added) do |method_name_arg|
      if Injections::DoubleInjection.exists?(memoized_subject, method_name_arg)
        Injections::DoubleInjection.create(memoized_subject, method_name_arg).send(:deferred_bind_method)
      end
      send(memoized_original_method_alias_name, method_name_arg)
    end
  end
  self
end
reset() click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 45
def reset
  if subject_has_method_defined?(original_method_alias_name)
    memoized_original_method_alias_name = original_method_alias_name
    placeholder_method_defined = @placeholder_method_defined
    subject_class.class_eval do
      remove_method :singleton_method_added
      unless placeholder_method_defined
        alias_method :singleton_method_added, memoized_original_method_alias_name
      end
      remove_method memoized_original_method_alias_name
    end
  end
end
singleton_method_added(method_name) click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 26
def singleton_method_added(method_name)
  super
end

Protected Instance Methods

original_method_alias_name() click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 64
def original_method_alias_name
  "__rr__original_singleton_method_added"
end
subject_class() click to toggle source
# File lib/rr/injections/singleton_method_added_injection.rb, line 60
def subject_class
  class << subject; self; end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.