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.
5863 5864 5865 5866 5867 5868 5869 |
# File 'lib/syntax_tree.rb', line 5863 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
5861 5862 5863 |
# File 'lib/syntax_tree.rb', line 5861 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5858 5859 5860 |
# File 'lib/syntax_tree.rb', line 5858 def location @location end |
#name ⇒ Object (readonly)
- Const | Ident
-
the name of the field being assigned
5855 5856 5857 |
# File 'lib/syntax_tree.rb', line 5855 def name @name end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used for the assignment
5852 5853 5854 |
# File 'lib/syntax_tree.rb', line 5852 def operator @operator end |
#parent ⇒ Object (readonly)
- untyped
-
the parent object that owns the field being assigned
5849 5850 5851 |
# File 'lib/syntax_tree.rb', line 5849 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object
5871 5872 5873 |
# File 'lib/syntax_tree.rb', line 5871 def child_nodes [parent, (operator if operator != :"::"), name] end |
#format(q) ⇒ Object
5875 5876 5877 5878 5879 5880 5881 |
# File 'lib/syntax_tree.rb', line 5875 def format(q) q.group do q.format(parent) q.format(CallOperatorFormatter.new(operator)) q.format(name) end end |
#pretty_print(q) ⇒ Object
5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 |
# File 'lib/syntax_tree.rb', line 5883 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
5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 |
# File 'lib/syntax_tree.rb', line 5900 def to_json(*opts) { type: :field, parent: parent, op: operator, name: name, loc: location, cmts: comments }.to_json(*opts) end |