Class: MarkdownRubyDocumentation::Method
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::Method
show all
- Defined in:
- lib/markdown_ruby_documentation/method.rb
Constant Summary
collapse
- InvalidMethodReference =
Class.new(StandardError)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(method_reference, context: Kernel, visibility: :public) ⇒ Method
Returns a new instance of Method.
7
8
9
10
11
|
# File 'lib/markdown_ruby_documentation/method.rb', line 7
def initialize(method_reference, context: Kernel, visibility: :public)
@method_reference = method_reference.to_s
@context = context
@visibility = visibility
end
|
Instance Attribute Details
#visibility ⇒ Object
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
45
46
47
48
49
50
51
|
# File 'lib/markdown_ruby_documentation/method.rb', line 45
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) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/markdown_ruby_documentation/method.rb', line 19
def self.create(method_reference, null_method: false, context: Kernel, visibility: :public)
return method_reference if method_reference.is_a?(Method)
case method_reference
when InstanceMethod
InstanceMethod.new(method_reference, context: context, visibility: visibility)
when ClassMethod
ClassMethod.new(method_reference, context: context, visibility: visibility)
else
if null_method
NullMethod.new(method_reference, context: context, visibility: visibility)
else
raise InvalidMethodReference, "method_reference is formatted incorrectly: '#{method_reference}'"
end
end
end
|
Instance Method Details
#==(other_method) ⇒ Object
Also known as:
eql?
35
36
37
|
# File 'lib/markdown_ruby_documentation/method.rb', line 35
def ==(other_method)
self.class == other_method.class && other_method.method_reference == self.method_reference
end
|
#context ⇒ Class
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/markdown_ruby_documentation/method.rb', line 59
def context
if method_reference.start_with?(type_symbol)
@context
else
constant = method_reference.split(type_symbol).first
begin
constant.constantize
rescue NameError => e
@context.const_get(constant)
end
end
end
|
#context_name ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/markdown_ruby_documentation/method.rb', line 72
def context_name
if method_reference.start_with?(type_symbol)
@context.name
else
method_reference.split(type_symbol).first
end
end
|
#hash ⇒ Object
41
42
43
|
# File 'lib/markdown_ruby_documentation/method.rb', line 41
def hash
@method_reference.hash
end
|
#inspect ⇒ String
91
92
93
|
# File 'lib/markdown_ruby_documentation/method.rb', line 91
def inspect
"#<#{self.class.name} #{to_s}>"
end
|
#name ⇒ Symbol
81
82
83
|
# File 'lib/markdown_ruby_documentation/method.rb', line 81
def name
method_reference.split(type_symbol).last.try!(:to_sym)
end
|
#to_proc ⇒ Proc
96
97
98
|
# File 'lib/markdown_ruby_documentation/method.rb', line 96
def to_proc
context.public_send(type, name)
end
|
#to_s ⇒ String
86
87
88
|
# File 'lib/markdown_ruby_documentation/method.rb', line 86
def to_s
method_reference
end
|
#type ⇒ Object
100
101
102
|
# File 'lib/markdown_ruby_documentation/method.rb', line 100
def type
raise NotImplementedError
end
|
#type_symbol ⇒ String
54
55
56
|
# File 'lib/markdown_ruby_documentation/method.rb', line 54
def type_symbol
self.class.type_symbol
end
|