Class: Luoma::StaticAnalysis::VariableMap
- Inherits:
-
Object
- Object
- Luoma::StaticAnalysis::VariableMap
- Defined in:
- lib/luoma/static_analysis.rb,
sig/luoma/static_analysis.rbs
Overview
Helper to group variables by their root segment during static analysis.
Instance Attribute Summary collapse
-
#data ⇒ Hash[String, Array[StaticVariable]]
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](var) ⇒ Array[StaticVariable]?
- #add(var) ⇒ void
-
#initialize ⇒ VariableMap
constructor
A new instance of VariableMap.
-
#to_h ⇒ Object
() -> Hash[String, Array[_Var]].
Constructor Details
#initialize ⇒ VariableMap
Returns a new instance of VariableMap.
152 153 154 |
# File 'lib/luoma/static_analysis.rb', line 152 def initialize @data = {} end |
Instance Attribute Details
#data ⇒ Hash[String, Array[StaticVariable]] (readonly)
Returns the value of attribute data.
150 151 152 |
# File 'lib/luoma/static_analysis.rb', line 150 def data @data end |
Instance Method Details
#[](var) ⇒ Array[StaticVariable]?
156 157 158 159 160 |
# File 'lib/luoma/static_analysis.rb', line 156 def [](var) key = var.root @data[key] = [] unless @data.include?(key) @data[key] end |
#add(var) ⇒ void
This method returns an undefined value.
162 163 164 |
# File 'lib/luoma/static_analysis.rb', line 162 def add(var) send(:[], var) << var end |
#to_h ⇒ Object
() -> Hash[String, Array[_Var]]
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/luoma/static_analysis.rb', line 167 def to_h result = {} #: Hash[String, Array[untyped]] @data.each do |k, v| a = [] #: Array[untyped] v.each do |sv| start_line, start_column, end_line, end_column = sv.location.span a << { segments: sv.segments, path: sv.to_s, start_index: sv.location.token[1], end_index: sv.location.token[2], start_line: start_line, start_column: start_column, end_line: end_line, end_column: end_column, value: sv.location.value, template_name: sv.location.template.name } end result[k] = a end result end |