Class: Method

Inherits:
Object show all
Includes:
MethodTrace::MethodAdditions
Defined in:
lib/method_trace.rb

Instance Method Summary collapse

Methods included from MethodTrace::MethodAdditions

included

Instance Method Details

#definitionObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/method_trace.rb', line 123

def definition
  @definition ||= begin
    if source.is_a?(Class)
      # if class: base class singleton methods
      source.class_hierarchy.each do |cls|
        d = MethodTrace::MethodDefinition.definition_sites["#{cls.object_id}::#{self.name}"]
        @from = cls and return d if d
      end
    else
      # singleton methods
      d = MethodTrace::MethodDefinition.definition_sites["#{source.object_id}::#{self.name}"]
      @from = 'singleton' and return d if d
    end
    
    # base class methods
    source.class.class_hierarchy.each do |cls|
      d = MethodTrace::MethodDefinition.definition_sites["#{cls.object_id}##{self.name}"]
      @from = cls and return d if d
    end
    
    # module methods
    source.usable_modules.each do |mod|
      d = MethodTrace::MethodDefinition.definition_sites["#{mod.object_id}##{self.name}"]
      @from = mod and return d if d
    end

    ['unknown']
  end
end