Class: YARD::CodeObjects::MethodObject
- Defined in:
- lib/yard/code_objects/method_object.rb
Overview
Represents a Ruby method in source
Instance Attribute Summary collapse
-
#explicit ⇒ Boolean
Whether the object is explicitly defined in source or whether it was inferred by a handler.
-
#parameters ⇒ Array<Array(String, String)>
Returns the list of parameters parsed out of the method signature with their default values.
-
#scope ⇒ Symbol
The scope of the method (
:class
or:instance
). -
#visibility ⇒ Symbol
The visibility of the method (
:public:
,:protected
,:private
).
Attributes inherited from Base
#docstring, #dynamic, #files, #group, #namespace, #signature, #source, #source_type
Instance Method Summary collapse
-
#aliases ⇒ Array<Symbol>
Returns all alias names of the object.
-
#attr_info ⇒ SymbolHash?
Returns the read/writer info for the attribute if it is one.
-
#constructor? ⇒ Boolean
Whether or not the method is the #initialize constructor method.
-
#initialize(namespace, name, scope = :instance) ⇒ MethodObject
constructor
Creates a new method object in
namespace
withname
and an instance or classscope
. -
#is_alias? ⇒ Boolean
Tests if the object is defined as an alias of another method.
-
#is_attribute? ⇒ Boolean
Tests if the object is defined as an attribute in the namespace.
-
#is_explicit? ⇒ Boolean
Tests boolean #explicit value.
-
#name(prefix = false) ⇒ String, Symbol
Returns the name of the object.
- #overridden_method ⇒ MethodObject?
-
#path ⇒ String
Override path handling for instance methods in the root namespace (they should still have a separator as a prefix).
-
#reader? ⇒ Boolean
Whether the method is a reader attribute.
-
#sep ⇒ String
protected
Override separator to differentiate between class and instance methods.
-
#writer? ⇒ Boolean
Whether the method is a writer attribute.
Methods inherited from Base
===, #[], #[]=, #add_file, #dynamic?, #equal?, #file, #format, #format_source, #has_tag?, #hash, #inspect, #line, #method_missing, new, #relative_path, #root?, #tag, #tags, #type
Constructor Details
#initialize(namespace, name, scope = :instance) ⇒ MethodObject
Creates a new method object in namespace
with name
and an instance or class scope
34 35 36 37 38 39 40 41 |
# File 'lib/yard/code_objects/method_object.rb', line 34 def initialize(namespace, name, scope = :instance) @scope = nil self.visibility = :public self.scope = scope self.parameters = [] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class YARD::CodeObjects::Base
Instance Attribute Details
#explicit ⇒ Boolean
Whether the object is explicitly defined in source or whether it was inferred by a handler. For instance, attribute methods are generally inferred and therefore not explicitly defined in source.
19 20 21 |
# File 'lib/yard/code_objects/method_object.rb', line 19 def explicit @explicit end |
#parameters ⇒ Array<Array(String, String)>
Returns the list of parameters parsed out of the method signature with their default values.
26 27 28 |
# File 'lib/yard/code_objects/method_object.rb', line 26 def parameters @parameters end |
#scope ⇒ Symbol
The scope of the method (:class
or :instance
)
12 13 14 |
# File 'lib/yard/code_objects/method_object.rb', line 12 def scope @scope end |
#visibility ⇒ Symbol
The visibility of the method (:public:
, :protected
, :private
)
7 8 9 |
# File 'lib/yard/code_objects/method_object.rb', line 7 def visibility @visibility end |
Instance Method Details
#aliases ⇒ Array<Symbol>
Returns all alias names of the object
113 114 115 116 117 118 119 120 |
# File 'lib/yard/code_objects/method_object.rb', line 113 def aliases list = [] return list unless namespace.is_a?(NamespaceObject) namespace.aliases.each do |o, aname| list << o if aname == name && o.scope == scope end list end |
#attr_info ⇒ SymbolHash?
Returns the read/writer info for the attribute if it is one
65 66 67 68 |
# File 'lib/yard/code_objects/method_object.rb', line 65 def attr_info return nil unless namespace.is_a?(NamespaceObject) namespace.attributes[scope][name.to_s.gsub(/=$/, '')] end |
#constructor? ⇒ Boolean
Returns whether or not the method is the #initialize constructor method.
57 58 59 |
# File 'lib/yard/code_objects/method_object.rb', line 57 def constructor? name == :initialize && scope == :instance && namespace.is_a?(ClassObject) end |
#is_alias? ⇒ Boolean
Tests if the object is defined as an alias of another method
91 92 93 94 |
# File 'lib/yard/code_objects/method_object.rb', line 91 def is_alias? return false unless namespace.is_a?(NamespaceObject) namespace.aliases.has_key? self end |
#is_attribute? ⇒ Boolean
Tests if the object is defined as an attribute in the namespace
84 85 86 87 |
# File 'lib/yard/code_objects/method_object.rb', line 84 def is_attribute? return false unless info = attr_info info[name.to_s =~ /=$/ ? :write : :read] ? true : false end |
#is_explicit? ⇒ Boolean
Tests boolean #explicit value.
99 100 101 |
# File 'lib/yard/code_objects/method_object.rb', line 99 def is_explicit? explicit ? true : false end |
#name(prefix = false) ⇒ String, Symbol
Returns the name of the object.
143 144 145 |
# File 'lib/yard/code_objects/method_object.rb', line 143 def name(prefix = false) prefix ? (sep == ISEP ? "#{sep}#{super}" : super.to_s) : super end |
#overridden_method ⇒ MethodObject?
106 107 108 109 |
# File 'lib/yard/code_objects/method_object.rb', line 106 def overridden_method meths = namespace.meths(:all => true) meths.find {|m| m.path != path && m.name == name && m.scope == scope } end |
#path ⇒ String
Override path handling for instance methods in the root namespace (they should still have a separator as a prefix).
125 126 127 128 129 130 131 |
# File 'lib/yard/code_objects/method_object.rb', line 125 def path if !namespace || namespace.path == "" sep + super else super end end |
#reader? ⇒ Boolean
Returns whether the method is a reader attribute.
78 79 80 |
# File 'lib/yard/code_objects/method_object.rb', line 78 def reader? !!((info = attr_info) && info[:read] == self) end |
#sep ⇒ String (protected)
Override separator to differentiate between class and instance methods.
152 153 154 155 156 157 158 |
# File 'lib/yard/code_objects/method_object.rb', line 152 def sep if scope == :class namespace && namespace != YARD::Registry.root ? CSEP : NSEP else ISEP end end |
#writer? ⇒ Boolean
Returns whether the method is a writer attribute.
72 73 74 |
# File 'lib/yard/code_objects/method_object.rb', line 72 def writer? !!((info = attr_info) && info[:write] == self) end |