Class: Inch::Language::Ruby::Provider::YARD::Object::MethodSignature
- Inherits:
-
Struct
- Object
- Struct
- Inch::Language::Ruby::Provider::YARD::Object::MethodSignature
- Defined in:
- lib/inch/language/ruby/provider/yard/object/method_signature.rb
Overview
Utility class to describe (overloaded) method signatures
Instance Attribute Summary collapse
-
#docstring ⇒ Object
readonly
Returns the value of attribute docstring.
-
#method ⇒ Object
Returns the value of attribute method.
-
#yard_tag ⇒ Object
Returns the value of attribute yard_tag.
Instance Method Summary collapse
- #all_signature_parameter_names ⇒ Object
- #has_code_example? ⇒ Boolean
- #has_doc? ⇒ Boolean
-
#initialize(method, yard_tag = nil) ⇒ MethodSignature
constructor
A new instance of MethodSignature.
-
#parameter(name) ⇒ MethodParameterObject
Returns the parameter with the given
name
. - #parameters ⇒ Object
-
#same?(other) ⇒ Boolean
Returns
true
if the other signature is identical to self. -
#signature ⇒ String
Returns the actual signature of the method.
Constructor Details
#initialize(method, yard_tag = nil) ⇒ MethodSignature
Returns a new instance of MethodSignature.
14 15 16 17 18 19 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 14 def initialize(method, yard_tag = nil) @method = method @yard_tag = yard_tag @docstring = Provider::YARD::Docstring.new(relevant_object.docstring) end |
Instance Attribute Details
#docstring ⇒ Object (readonly)
Returns the value of attribute docstring.
9 10 11 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 9 def docstring @docstring end |
#method ⇒ Object
Returns the value of attribute method
8 9 10 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 8 def method @method end |
#yard_tag ⇒ Object
Returns the value of attribute yard_tag
8 9 10 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 8 def yard_tag @yard_tag end |
Instance Method Details
#all_signature_parameter_names ⇒ Object
21 22 23 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 21 def all_signature_parameter_names (relevant_object.parameters || []).map(&:first) end |
#has_code_example? ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 25 def has_code_example? if docstring.contains_code_example? true else !relevant_object.(:example).empty? end end |
#has_doc? ⇒ Boolean
33 34 35 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 33 def has_doc? !docstring.empty? && !implicit_docstring? end |
#parameter(name) ⇒ MethodParameterObject
Returns the parameter with the given name
.
48 49 50 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 48 def parameter(name) parameters.find { |p| p.name == name.to_s } end |
#parameters ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 37 def parameters @parameters ||= all_parameter_names.map do |name| signature_name = in_signature(name) tag = parameter_tag(name) || parameter_tag(signature_name) MethodParameterObject.new(method, name, signature_name, tag) end end |
#same?(other) ⇒ Boolean
Returns true
if the other signature is identical to self
55 56 57 58 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 55 def same?(other) all_signature_parameter_names == other.all_signature_parameter_names end |
#signature ⇒ String
Returns the actual signature of the method.
62 63 64 |
# File 'lib/inch/language/ruby/provider/yard/object/method_signature.rb', line 62 def signature relevant_object.signature.gsub(/^(def\ )/, '') end |