Class: SyntaxTree::Not
Overview
Not represents the unary not method being called on an expression.
not value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#parentheses ⇒ Object
readonly
- boolean
-
whether or not parentheses were used.
-
#statement ⇒ Object
readonly
- nil | untyped
-
the statement on which to operate.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, parentheses:, location:, comments: []) ⇒ Not
constructor
A new instance of Not.
Methods inherited from Node
Constructor Details
#initialize(statement:, parentheses:, location:, comments: []) ⇒ Not
Returns a new instance of Not.
8723 8724 8725 8726 8727 8728 |
# File 'lib/syntax_tree/node.rb', line 8723 def initialize(statement:, parentheses:, location:, comments: []) @statement = statement @parentheses = parentheses @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8721 8722 8723 |
# File 'lib/syntax_tree/node.rb', line 8721 def comments @comments end |
#parentheses ⇒ Object (readonly)
- boolean
-
whether or not parentheses were used
8718 8719 8720 |
# File 'lib/syntax_tree/node.rb', line 8718 def parentheses @parentheses end |
#statement ⇒ Object (readonly)
- nil | untyped
-
the statement on which to operate
8715 8716 8717 |
# File 'lib/syntax_tree/node.rb', line 8715 def statement @statement end |
Instance Method Details
#accept(visitor) ⇒ Object
8730 8731 8732 |
# File 'lib/syntax_tree/node.rb', line 8730 def accept(visitor) visitor.visit_not(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8734 8735 8736 |
# File 'lib/syntax_tree/node.rb', line 8734 def child_nodes [statement] end |
#deconstruct_keys(keys) ⇒ Object
8740 8741 8742 8743 8744 8745 8746 8747 |
# File 'lib/syntax_tree/node.rb', line 8740 def deconstruct_keys(keys) { statement: statement, parentheses: parentheses, location: location, comments: comments } end |
#format(q) ⇒ Object
8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 |
# File 'lib/syntax_tree/node.rb', line 8749 def format(q) parent = q.parents.take(2)[1] ternary = (parent.is_a?(If) || parent.is_a?(Unless)) && Ternaryable.call(q, parent) q.text("not") if parentheses q.text("(") elsif ternary q.if_break { q.text(" ") }.if_flat { q.text("(") } else q.text(" ") end q.format(statement) if statement if parentheses q.text(")") elsif ternary q.if_flat { q.text(")") } end end |