Class: SyntaxTree::Assign
- Inherits:
-
Object
- Object
- SyntaxTree::Assign
- Defined in:
- lib/syntax_tree.rb
Overview
Assign represents assigning something to a variable or constant. Generally, the left side of the assignment is going to be any node that ends with the name “Field”.
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.
-
#target ⇒ Object
readonly
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target to assign the result of the expression to.
-
#value ⇒ Object
readonly
- untyped
-
the expression to be assigned.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:, comments: []) ⇒ Assign
constructor
A new instance of Assign.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, value:, location:, comments: []) ⇒ Assign
Returns a new instance of Assign.
1817 1818 1819 1820 1821 1822 |
# File 'lib/syntax_tree.rb', line 1817 def initialize(target:, value:, location:, comments: []) @target = target @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1815 1816 1817 |
# File 'lib/syntax_tree.rb', line 1815 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
1812 1813 1814 |
# File 'lib/syntax_tree.rb', line 1812 def location @location end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
1806 1807 1808 |
# File 'lib/syntax_tree.rb', line 1806 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
1809 1810 1811 |
# File 'lib/syntax_tree.rb', line 1809 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
1824 1825 1826 |
# File 'lib/syntax_tree.rb', line 1824 def child_nodes [target, value] end |
#format(q) ⇒ Object
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 |
# File 'lib/syntax_tree.rb', line 1828 def format(q) q.group do q.format(target) q.text(" =") if skip_indent? q.text(" ") q.format(value) else q.indent do q.breakable q.format(value) end end end end |
#pretty_print(q) ⇒ Object
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 |
# File 'lib/syntax_tree.rb', line 1845 def pretty_print(q) q.group(2, "(", ")") do q.text("assign") q.breakable q.pp(target) q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1859 1860 1861 1862 1863 1864 1865 1866 1867 |
# File 'lib/syntax_tree.rb', line 1859 def to_json(*opts) { type: :assign, target: target, value: value, loc: location, cmts: comments }.to_json(*opts) end |