Class: Parser::Source::Map

Inherits:
Object
  • Object
show all
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.

Defined Under Namespace

Classes: Block, Collection, Condition, Constant, Definition, For, Keyword, Operator, RescueBody, Send, Ternary, Variable

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#expressionObject (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

#lineObject



18
19
20
# File 'lib/parser/source/map.rb', line 18

def line
  @expression.line
end

#to_hashObject



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