Class: SyntaxTree::Else
- Inherits:
-
Object
- Object
- SyntaxTree::Else
- Defined in:
- lib/syntax_tree.rb
Overview
Else represents the end of an if, unless, or case chain.
if variable
else
end
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.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ Else
constructor
A new instance of Else.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ Else
Returns a new instance of Else.
4956 4957 4958 4959 4960 |
# File 'lib/syntax_tree.rb', line 4956 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4954 4955 4956 |
# File 'lib/syntax_tree.rb', line 4954 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4951 4952 4953 |
# File 'lib/syntax_tree.rb', line 4951 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
4948 4949 4950 |
# File 'lib/syntax_tree.rb', line 4948 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
4962 4963 4964 |
# File 'lib/syntax_tree.rb', line 4962 def child_nodes [statements] end |
#format(q) ⇒ Object
4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 |
# File 'lib/syntax_tree.rb', line 4966 def format(q) q.group do q.text("else") unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end end |
#pretty_print(q) ⇒ Object
4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 |
# File 'lib/syntax_tree.rb', line 4979 def pretty_print(q) q.group(2, "(", ")") do q.text("else") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4990 4991 4992 4993 4994 |
# File 'lib/syntax_tree.rb', line 4990 def to_json(*opts) { type: :else, stmts: statements, loc: location, cmts: comments }.to_json( *opts ) end |