Class: ClassSource::MethodIndex
- Inherits:
-
Object
- Object
- ClassSource::MethodIndex
- Defined in:
- lib/class_source/method_index.rb
Overview
An index of all the methods in the target class
Instance Method Summary collapse
-
#all(options = {}) ⇒ Array
An array of method names for all instance methods in the class.
-
#initialize(target_class) ⇒ MethodIndex
constructor
A new instance of MethodIndex.
-
#klass ⇒ ClassSource::ClassMethodIndex
A index of class methods.
-
#locations ⇒ Array
An array of [file_path, line_number] tuples for all unique methods of the class.
-
#unique ⇒ Array
An array of method names unique to or overridden in this class, not inherited from its ancestors or singleton_class ancestors.
Constructor Details
#initialize(target_class) ⇒ MethodIndex
Returns a new instance of MethodIndex.
4 5 6 |
# File 'lib/class_source/method_index.rb', line 4 def initialize(target_class) @target_class = target_class end |
Instance Method Details
#all(options = {}) ⇒ Array
Returns An array of method names for all instance methods in the class.
29 30 31 32 33 34 35 |
# File 'lib/class_source/method_index.rb', line 29 def all(={}) include_inherited_methods = .has_key?(:include_inherited_methods) ? [:include_inherited_methods] : true target = [:target] || @target_class target.public_instance_methods(include_inherited_methods) + target.private_instance_methods(include_inherited_methods) + target.protected_instance_methods(include_inherited_methods) end |
#klass ⇒ ClassSource::ClassMethodIndex
Returns A index of class methods.
39 40 41 |
# File 'lib/class_source/method_index.rb', line 39 def klass ClassMethodIndex.new(@target_class) end |
#locations ⇒ Array
Returns An array of [file_path, line_number] tuples for all unique methods of the class.
10 11 12 13 14 15 16 |
# File 'lib/class_source/method_index.rb', line 10 def locations @locations ||= (unique.map do |m| @target_class.instance_method(m).source_location end + klass.unique.map do |m| @target_class.method(m).source_location end).compact end |
#unique ⇒ Array
Returns An array of method names unique to or overridden in this class, not inherited from its ancestors or singleton_class ancestors.
19 20 21 22 23 24 25 |
# File 'lib/class_source/method_index.rb', line 19 def unique uniquely_named_methods = all(:include_inherited_methods => false) overridden_methods = (all - uniquely_named_methods).select do |m| @target_class.instance_method(m).source_location != @target_class.superclass.instance_method(m).source_location end overridden_methods + uniquely_named_methods end |