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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(statement:, parentheses:, location:, comments: []) ⇒ Not
Returns a new instance of Not.
9007 9008 9009 9010 9011 9012 |
# File 'lib/syntax_tree/node.rb', line 9007 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
9005 9006 9007 |
# File 'lib/syntax_tree/node.rb', line 9005 def comments @comments end |
#parentheses ⇒ Object (readonly)
- boolean
-
whether or not parentheses were used
9002 9003 9004 |
# File 'lib/syntax_tree/node.rb', line 9002 def parentheses @parentheses end |
#statement ⇒ Object (readonly)
- nil | untyped
-
the statement on which to operate
8999 9000 9001 |
# File 'lib/syntax_tree/node.rb', line 8999 def statement @statement end |
Instance Method Details
#accept(visitor) ⇒ Object
9014 9015 9016 |
# File 'lib/syntax_tree/node.rb', line 9014 def accept(visitor) visitor.visit_not(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9018 9019 9020 |
# File 'lib/syntax_tree/node.rb', line 9018 def child_nodes [statement] end |
#deconstruct_keys(_keys) ⇒ Object
9024 9025 9026 9027 9028 9029 9030 9031 |
# File 'lib/syntax_tree/node.rb', line 9024 def deconstruct_keys(_keys) { statement: statement, parentheses: parentheses, location: location, comments: comments } end |
#format(q) ⇒ Object
9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 |
# File 'lib/syntax_tree/node.rb', line 9033 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 |