Class: MarkdownRubyDocumentation::Method
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::Method
- Defined in:
- lib/markdown_ruby_documentation/method.rb
Direct Known Subclasses
Constant Summary collapse
- InvalidMethodReference =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#line_no ⇒ Object
Returns the value of attribute line_no.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Class Method Summary collapse
- .===(value) ⇒ Object
- .create(method_reference, null_method: false, context: Kernel, visibility: :public, file_path: nil) ⇒ Object
Instance Method Summary collapse
- #==(other_method) ⇒ Object (also: #eql?)
- #context ⇒ Class
- #context_name ⇒ Object
- #hash ⇒ Object
-
#initialize(method_reference, context: Kernel, visibility: :public, file_path: nil, line_no: nil) ⇒ Method
constructor
A new instance of Method.
- #inspect ⇒ String
- #name ⇒ Symbol
- #source_location ⇒ Object
- #to_proc ⇒ Proc
- #to_s ⇒ String
- #type ⇒ Object
- #type_symbol ⇒ String
Constructor Details
#initialize(method_reference, context: Kernel, visibility: :public, file_path: nil, line_no: nil) ⇒ Method
Returns a new instance of Method.
8 9 10 11 12 13 14 |
# File 'lib/markdown_ruby_documentation/method.rb', line 8 def initialize(method_reference, context: Kernel, visibility: :public, file_path: nil, line_no: nil) @method_reference = method_reference.to_s @context = context @visibility = visibility @file_path = file_path @line_no = line_no end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/markdown_ruby_documentation/method.rb', line 5 def file_path @file_path end |
#line_no ⇒ Object
Returns the value of attribute line_no.
5 6 7 |
# File 'lib/markdown_ruby_documentation/method.rb', line 5 def line_no @line_no end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
4 5 6 |
# File 'lib/markdown_ruby_documentation/method.rb', line 4 def visibility @visibility end |
Class Method Details
.===(value) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/markdown_ruby_documentation/method.rb', line 48 def self.===(value) if value.is_a?(String) value.include?(type_symbol) && !!/\A[:A-Za-z_0-9!?#{type_symbol}]+\z/.match(value) else super end end |
.create(method_reference, null_method: false, context: Kernel, visibility: :public, file_path: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/markdown_ruby_documentation/method.rb', line 22 def self.create(method_reference, null_method: false, context: Kernel, visibility: :public, file_path: nil) return method_reference if method_reference.is_a?(Method) case method_reference when InstanceMethod InstanceMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path) when ClassMethod ClassMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path) else if null_method NullMethod.new(method_reference, context: context, visibility: visibility, file_path: file_path) else raise InvalidMethodReference, "method_reference is formatted incorrectly: '#{method_reference}'" end end end |
Instance Method Details
#==(other_method) ⇒ Object Also known as: eql?
38 39 40 |
# File 'lib/markdown_ruby_documentation/method.rb', line 38 def ==(other_method) self.class == other_method.class && other_method.method_reference == self.method_reference end |
#context ⇒ Class
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/markdown_ruby_documentation/method.rb', line 62 def context if method_reference.start_with?(type_symbol) @context else constant = method_reference.split(type_symbol).first begin constant.constantize rescue NameError @context.const_get(constant) end end end |
#context_name ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/markdown_ruby_documentation/method.rb', line 75 def context_name if method_reference.start_with?(type_symbol) @context.name else method_reference.split(type_symbol).first end end |
#hash ⇒ Object
44 45 46 |
# File 'lib/markdown_ruby_documentation/method.rb', line 44 def hash @method_reference.hash end |
#inspect ⇒ String
94 95 96 |
# File 'lib/markdown_ruby_documentation/method.rb', line 94 def inspect "#<#{self.class.name} #{to_s}>" end |
#name ⇒ Symbol
84 85 86 |
# File 'lib/markdown_ruby_documentation/method.rb', line 84 def name method_reference.split(type_symbol).last.try!(:to_sym) end |
#source_location ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/markdown_ruby_documentation/method.rb', line 103 def source_location if file_path && line_no [file_path, line_no] else context.public_send(type, name).source_location end end |
#to_proc ⇒ Proc
99 100 101 |
# File 'lib/markdown_ruby_documentation/method.rb', line 99 def to_proc context.public_send(type, name) end |
#to_s ⇒ String
89 90 91 |
# File 'lib/markdown_ruby_documentation/method.rb', line 89 def to_s method_reference end |
#type ⇒ Object
111 112 113 |
# File 'lib/markdown_ruby_documentation/method.rb', line 111 def type raise NotImplementedError end |
#type_symbol ⇒ String
57 58 59 |
# File 'lib/markdown_ruby_documentation/method.rb', line 57 def type_symbol self.class.type_symbol end |