Class: SyntaxTree::Dot3
- Inherits:
-
Object
- Object
- SyntaxTree::Dot3
- Defined in:
- lib/syntax_tree.rb
Overview
Dot3 represents using the … operator between two expressions. Usually this is to create a range object. It’s effectively the same event as the Dot2 node but with this operator you’re asking Ruby to omit the final value.
1...2
Like Dot2 it can also be used to create a flip-flop.
if value == 5 ... value == 10
end
One of the sides of the expression may be nil, but not both.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- nil | untyped
-
the left side of the expression.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#right ⇒ Object
readonly
- nil | untyped
-
the right side of the expression.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ Dot3
constructor
A new instance of Dot3.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ Dot3
Returns a new instance of Dot3.
5034 5035 5036 5037 5038 5039 |
# File 'lib/syntax_tree.rb', line 5034 def initialize(left:, right:, location:, comments: []) @left = left @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5032 5033 5034 |
# File 'lib/syntax_tree.rb', line 5032 def comments @comments end |
#left ⇒ Object (readonly)
- nil | untyped
-
the left side of the expression
5023 5024 5025 |
# File 'lib/syntax_tree.rb', line 5023 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5029 5030 5031 |
# File 'lib/syntax_tree.rb', line 5029 def location @location end |
#right ⇒ Object (readonly)
- nil | untyped
-
the right side of the expression
5026 5027 5028 |
# File 'lib/syntax_tree.rb', line 5026 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
5041 5042 5043 |
# File 'lib/syntax_tree.rb', line 5041 def child_nodes [left, right] end |
#format(q) ⇒ Object
5045 5046 5047 |
# File 'lib/syntax_tree.rb', line 5045 def format(q) DotFormatter.new("...", self).format(q) end |
#pretty_print(q) ⇒ Object
5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 |
# File 'lib/syntax_tree.rb', line 5049 def pretty_print(q) q.group(2, "(", ")") do q.text("dot3") if left q.breakable q.pp(left) end if right q.breakable q.pp(right) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5067 5068 5069 5070 5071 5072 5073 5074 5075 |
# File 'lib/syntax_tree.rb', line 5067 def to_json(*opts) { type: :dot3, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |