Class: Luoma::StaticAnalysis::StaticVariable
- Inherits:
-
Object
- Object
- Luoma::StaticAnalysis::StaticVariable
- Defined in:
- lib/luoma/static_analysis.rb,
sig/luoma/static_analysis.rbs
Overview
A variable as a sequence of segments and its location.
Constant Summary collapse
- RE_PROPERTY =
/\A[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*\Z/
Instance Attribute Summary collapse
-
#location ⇒ Location
readonly
Returns the value of attribute location.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Object
-
#initialize(segments, location) ⇒ StaticVariable
constructor
A new instance of StaticVariable.
-
#root ⇒ String
() -> String.
- #segments_to_s(segments) ⇒ String
- #to_s ⇒ String
Constructor Details
#initialize(segments, location) ⇒ StaticVariable
Returns a new instance of StaticVariable.
75 76 77 78 |
# File 'lib/luoma/static_analysis.rb', line 75 def initialize(segments, location) @segments = segments @location = location end |
Instance Attribute Details
#location ⇒ Location (readonly)
Returns the value of attribute location.
71 72 73 |
# File 'lib/luoma/static_analysis.rb', line 71 def location @location end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
71 72 73 |
# File 'lib/luoma/static_analysis.rb', line 71 def segments @segments end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
84 85 86 87 |
# File 'lib/luoma/static_analysis.rb', line 84 def ==(other) self.class == other.class && @segments == other.segments end |
#hash ⇒ Object
91 92 93 |
# File 'lib/luoma/static_analysis.rb', line 91 def hash @segments.hash end |
#root ⇒ String
() -> String
96 97 98 99 |
# File 'lib/luoma/static_analysis.rb', line 96 def root segment = @segments.first || "" segment.is_a?(Array) ? segments_to_s(segment) : segment.to_s end |
#segments_to_s(segments) ⇒ String
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/luoma/static_analysis.rb', line 103 def segments_to_s(segments) head, *rest = segments head.to_s + rest.map do |segment| case segment when Array "[#{segments_to_s(segment)}]" when String if segment.match?(RE_PROPERTY) || segment.end_with?("?") ".#{segment}" else "[#{segment.inspect}]" end else "[#{segment}]" end end.join end |
#to_s ⇒ String
80 81 82 |
# File 'lib/luoma/static_analysis.rb', line 80 def to_s segments_to_s(@segments) end |