Class: Estreet::Node
- Inherits:
-
Object
- Object
- Estreet::Node
- Defined in:
- lib/estreet/node.rb
Direct Known Subclasses
Expression, Program, Property, Statement, SwitchCase, VariableDeclarator
Instance Attribute Summary collapse
-
#source_location ⇒ Object
readonly
Returns the value of attribute source_location.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(loc = nil) ⇒ Node
constructor
A new instance of Node.
- #loc(source_location) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(loc = nil) ⇒ Node
Returns a new instance of Node.
6 7 8 |
# File 'lib/estreet/node.rb', line 6 def initialize(loc=nil) @source_location = loc end |
Instance Attribute Details
#source_location ⇒ Object (readonly)
Returns the value of attribute source_location.
4 5 6 |
# File 'lib/estreet/node.rb', line 4 def source_location @source_location end |
Instance Method Details
#as_json ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/estreet/node.rb', line 19 def as_json attributes.map {|k,v| case v when Estreet::Node [k, v.as_json] when Array [k, v.map(&:as_json)] else [k, v] end }.to_h # raise NotImplementedError end |
#loc(source_location) ⇒ Object
10 11 12 13 |
# File 'lib/estreet/node.rb', line 10 def loc(source_location) @source_location = loc # TODO: construct the thing self # suitable for chaining end |
#type ⇒ Object
15 16 17 |
# File 'lib/estreet/node.rb', line 15 def type self.class.name.gsub(/\AEstreet::/, '') end |