Class: SyntaxTree::Field
- Inherits:
-
Object
- Object
- SyntaxTree::Field
- Defined in:
- lib/syntax_tree.rb
Overview
Field is always the child of an assignment. It represents assigning to a “field” on an object.
object.variable = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#name ⇒ Object
readonly
- Const | Ident
-
the name of the field being assigned.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator being used for the assignment.
-
#parent ⇒ Object
readonly
- untyped
-
the parent object that owns the field being assigned.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
constructor
A new instance of Field.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parent:, operator:, name:, location:, comments: []) ⇒ Field
Returns a new instance of Field.
6032 6033 6034 6035 6036 6037 6038 |
# File 'lib/syntax_tree.rb', line 6032 def initialize(parent:, operator:, name:, location:, comments: []) @parent = parent @operator = operator @name = name @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6030 6031 6032 |
# File 'lib/syntax_tree.rb', line 6030 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6027 6028 6029 |
# File 'lib/syntax_tree.rb', line 6027 def location @location end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
6024 6025 6026 |
# File 'lib/syntax_tree.rb', line 6024 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
6021 6022 6023 |
# File 'lib/syntax_tree.rb', line 6021 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
6018 6019 6020 |
# File 'lib/syntax_tree.rb', line 6018 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object
6040 6041 6042 |
# File 'lib/syntax_tree.rb', line 6040 def child_nodes [parent, (operator if operator != :"::"), name] end |
#format(q) ⇒ Object
6044 6045 6046 6047 6048 6049 6050 |
# File 'lib/syntax_tree.rb', line 6044 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format(name) end end |
#pretty_print(q) ⇒ Object
6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 |
# File 'lib/syntax_tree.rb', line 6052 def pretty_print(q) q.group(2, "(", ")") do q.text("field") q.breakable q.pp(parent) q.breakable q.pp(operator) q.breakable q.pp(name) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 |
# File 'lib/syntax_tree.rb', line 6069 def to_json(*opts) { type: :field, parent: parent, op: operator, name: name, loc: location, cmts: comments }.to_json(*opts) end |