Class: SyntaxTree::Unless
- Inherits:
-
Object
- Object
- SyntaxTree::Unless
- Defined in:
- lib/syntax_tree.rb
Overview
Unless represents the first clause in an unless chain.
unless predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil, Elsif, Else
-
the next clause in the chain.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless
constructor
A new instance of Unless.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless
Returns a new instance of Unless.
11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 |
# File 'lib/syntax_tree.rb', line 11757 def initialize( predicate:, statements:, consequent:, location:, comments: [] ) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11755 11756 11757 |
# File 'lib/syntax_tree.rb', line 11755 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
11749 11750 11751 |
# File 'lib/syntax_tree.rb', line 11749 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11752 11753 11754 |
# File 'lib/syntax_tree.rb', line 11752 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
11743 11744 11745 |
# File 'lib/syntax_tree.rb', line 11743 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
11746 11747 11748 |
# File 'lib/syntax_tree.rb', line 11746 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
11771 11772 11773 |
# File 'lib/syntax_tree.rb', line 11771 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
11775 11776 11777 |
# File 'lib/syntax_tree.rb', line 11775 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#pretty_print(q) ⇒ Object
11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 |
# File 'lib/syntax_tree.rb', line 11779 def pretty_print(q) q.group(2, "(", ")") do q.text("unless") q.breakable q.pp(predicate) q.breakable q.pp(statements) if consequent q.breakable q.pp(consequent) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 |
# File 'lib/syntax_tree.rb', line 11798 def to_json(*opts) { type: :unless, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |