Class: Parser::Source::Map
- Inherits:
-
Object
- Object
- Parser::Source::Map
- Defined in:
- lib/parser/source/map.rb
Overview
General idea for Map subclasses: only store what's absolutely necessary; don't duplicate the info contained in ASTs; if it can be extracted from source given only the other stored information, don't store it.
Direct Known Subclasses
Block, Collection, Condition, Constant, Definition, For, Keyword, Operator, RescueBody, Send, Ternary, Variable
Defined Under Namespace
Classes: Block, Collection, Condition, Constant, Definition, For, Keyword, Operator, RescueBody, Send, Ternary, Variable
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Instance Method Summary collapse
-
#initialize(expression) ⇒ Map
constructor
A new instance of Map.
- #line ⇒ Object
- #to_hash ⇒ Object
- #update_expression(expression_l) ⇒ Object protected
- #with(&block) ⇒ Object protected
- #with_expression(expression_l) ⇒ Object
Constructor Details
#initialize(expression) ⇒ Map
Returns a new instance of Map.
12 13 14 15 16 |
# File 'lib/parser/source/map.rb', line 12 def initialize(expression) @expression = expression freeze end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
10 11 12 |
# File 'lib/parser/source/map.rb', line 10 def expression @expression end |
Instance Method Details
#line ⇒ Object
18 19 20 |
# File 'lib/parser/source/map.rb', line 18 def line @expression.line end |
#to_hash ⇒ Object
26 27 28 29 30 |
# File 'lib/parser/source/map.rb', line 26 def to_hash Hash[instance_variables.map do |ivar| [ ivar[1..-1].to_sym, instance_variable_get(ivar) ] end] end |
#update_expression(expression_l) ⇒ Object (protected)
38 39 40 |
# File 'lib/parser/source/map.rb', line 38 def update_expression(expression_l) @expression = expression_l end |
#with(&block) ⇒ Object (protected)
34 35 36 |
# File 'lib/parser/source/map.rb', line 34 def with(&block) dup.tap(&block).freeze end |
#with_expression(expression_l) ⇒ Object
22 23 24 |
# File 'lib/parser/source/map.rb', line 22 def with_expression(expression_l) with { |map| map.update_expression(expression_l) } end |