Class: YARD::CodeObjects::MethodObject
- Inherits:
-
Base
- Object
- Base
- YARD::CodeObjects::MethodObject
- Defined in:
- lib/yard/code_objects/method_object.rb
Overview
Represents a Ruby method in source
Instance Attribute Summary (collapse)
-
- (Boolean) explicit
Whether the object is explicitly defined in source or whether it was inferred by a handler.
-
- (Array<Array(String, String)>) parameters
Returns the list of parameters parsed out of the method signature with their default values.
-
- (Symbol) scope
The scope of the method (:class or :instance).
Attributes inherited from Base
docstring, dynamic, files, group, namespace, signature, source, source_type, visibility
Instance Method Summary (collapse)
-
- (Array<Symbol>) aliases
Returns all alias names of the object.
-
- (SymbolHash?) attr_info
Returns the read/writer info for the attribute if it is one.
-
- (Boolean) constructor?
Whether or not the method is the #initialize constructor method.
-
- (MethodObject) initialize(namespace, name, scope = :instance)
constructor
Creates a new method object in namespace with name and an instance or class scope.
-
- (Boolean) is_alias?
Tests if the object is defined as an alias of another method.
-
- (Boolean) is_attribute?
Tests if the object is defined as an attribute in the namespace.
-
- (Boolean) is_explicit?
Tests boolean #explicit value.
-
- (String, Symbol) name(prefix = false)
Returns the name of the object.
- - (MethodObject?) overridden_method
-
- (String) path
Override path handling for instance methods in the root namespace (they should still have a separator as a prefix).
-
- (Boolean) reader?
Whether the method is a reader attribute.
-
- (String) sep
protected
Override separator to differentiate between class and instance methods.
-
- (Boolean) writer?
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, #to_ary, #type
Constructor Details
- (MethodObject) initialize(namespace, name, scope = :instance)
Creates a new method object in namespace with name and an instance or class scope
29 30 31 32 33 34 35 36 |
# File 'lib/yard/code_objects/method_object.rb', line 29 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
- (Boolean) explicit
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.
14 15 16 |
# File 'lib/yard/code_objects/method_object.rb', line 14 def explicit @explicit end |
- (Array<Array(String, String)>) parameters
Returns the list of parameters parsed out of the method signature with their default values.
21 22 23 |
# File 'lib/yard/code_objects/method_object.rb', line 21 def parameters @parameters end |
- (Symbol) scope
The scope of the method (:class or :instance)
7 8 9 |
# File 'lib/yard/code_objects/method_object.rb', line 7 def scope @scope end |
Instance Method Details
- (Array<Symbol>) aliases
Returns all alias names of the object
106 107 108 109 110 111 112 113 |
# File 'lib/yard/code_objects/method_object.rb', line 106 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 |
- (SymbolHash?) attr_info
Returns the read/writer info for the attribute if it is one
57 58 59 60 |
# File 'lib/yard/code_objects/method_object.rb', line 57 def attr_info return nil unless namespace.is_a?(NamespaceObject) namespace.attributes[scope][name.to_s.gsub(/=$/, '')] end |
- (Boolean) constructor?
Whether or not the method is the #initialize constructor method
49 50 51 |
# File 'lib/yard/code_objects/method_object.rb', line 49 def constructor? name == :initialize && scope == :instance && namespace.is_a?(ClassObject) end |
- (Boolean) is_alias?
Tests if the object is defined as an alias of another method
83 84 85 86 |
# File 'lib/yard/code_objects/method_object.rb', line 83 def is_alias? return false unless namespace.is_a?(NamespaceObject) namespace.aliases.has_key? self end |
- (Boolean) is_attribute?
Tests if the object is defined as an attribute in the namespace
76 77 78 79 |
# File 'lib/yard/code_objects/method_object.rb', line 76 def is_attribute? return false unless info = attr_info info[name.to_s =~ /=$/ ? :write : :read] ? true : false end |
- (Boolean) is_explicit?
Tests boolean #explicit value.
91 92 93 |
# File 'lib/yard/code_objects/method_object.rb', line 91 def is_explicit? explicit ? true : false end |
- (String, Symbol) name(prefix = false)
Returns the name of the object.
136 137 138 |
# File 'lib/yard/code_objects/method_object.rb', line 136 def name(prefix = false) prefix ? (sep == ISEP ? "#{sep}#{super}" : super.to_s) : super end |
- (MethodObject?) overridden_method
98 99 100 101 102 |
# File 'lib/yard/code_objects/method_object.rb', line 98 def overridden_method return nil if namespace.is_a?(Proxy) meths = namespace.meths(:all => true) meths.find {|m| m.path != path && m.name == name && m.scope == scope } end |
- (String) path
Override path handling for instance methods in the root namespace (they should still have a separator as a prefix).
118 119 120 121 122 123 124 |
# File 'lib/yard/code_objects/method_object.rb', line 118 def path @path ||= if !namespace || namespace.path == "" sep + super else super end end |
- (Boolean) reader?
Whether the method is a reader attribute
70 71 72 |
# File 'lib/yard/code_objects/method_object.rb', line 70 def reader? !!((info = attr_info) && info[:read] == self) end |
- (String) sep (protected)
Override separator to differentiate between class and instance methods.
145 146 147 148 149 150 151 |
# File 'lib/yard/code_objects/method_object.rb', line 145 def sep if scope == :class namespace && namespace != YARD::Registry.root ? CSEP : NSEP else ISEP end end |
- (Boolean) writer?
Whether the method is a writer attribute
64 65 66 |
# File 'lib/yard/code_objects/method_object.rb', line 64 def writer? !!((info = attr_info) && info[:write] == self) end |