Class: SyntaxTree::Dot2
- Inherits:
-
Object
- Object
- SyntaxTree::Dot2
- Defined in:
- lib/syntax_tree.rb
Overview
Dot2 represents using the .. operator between two expressions. Usually this is to create a range object.
1..2
Sometimes this operator is 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: []) ⇒ Dot2
constructor
A new instance of Dot2.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ Dot2
Returns a new instance of Dot2.
4950 4951 4952 4953 4954 4955 |
# File 'lib/syntax_tree.rb', line 4950 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
4948 4949 4950 |
# File 'lib/syntax_tree.rb', line 4948 def comments @comments end |
#left ⇒ Object (readonly)
- nil | untyped
-
the left side of the expression
4939 4940 4941 |
# File 'lib/syntax_tree.rb', line 4939 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4945 4946 4947 |
# File 'lib/syntax_tree.rb', line 4945 def location @location end |
#right ⇒ Object (readonly)
- nil | untyped
-
the right side of the expression
4942 4943 4944 |
# File 'lib/syntax_tree.rb', line 4942 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
4957 4958 4959 |
# File 'lib/syntax_tree.rb', line 4957 def child_nodes [left, right] end |
#format(q) ⇒ Object
4961 4962 4963 |
# File 'lib/syntax_tree.rb', line 4961 def format(q) DotFormatter.new("..", self).format(q) end |
#pretty_print(q) ⇒ Object
4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 |
# File 'lib/syntax_tree.rb', line 4965 def pretty_print(q) q.group(2, "(", ")") do q.text("dot2") 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
4983 4984 4985 4986 4987 4988 4989 4990 4991 |
# File 'lib/syntax_tree.rb', line 4983 def to_json(*opts) { type: :dot2, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |