Class: SyntaxTree::Case
Overview
Case represents the beginning of a case chain.
case value
when 1
"one"
when 2
"two"
else
"number"
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- In | When
-
the next clause in the chain.
-
#keyword ⇒ Object
readonly
- Kw
-
the keyword that opens this expression.
-
#value ⇒ Object
readonly
- nil | untyped
-
optional value being switched on.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, value:, consequent:, location:, comments: []) ⇒ Case
constructor
A new instance of Case.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, value:, consequent:, location:, comments: []) ⇒ Case
Returns a new instance of Case.
2674 2675 2676 2677 2678 2679 2680 |
# File 'lib/syntax_tree/node.rb', line 2674 def initialize(keyword:, value:, consequent:, location:, comments: []) @keyword = keyword @value = value @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2672 2673 2674 |
# File 'lib/syntax_tree/node.rb', line 2672 def comments @comments end |
#consequent ⇒ Object (readonly)
- In | When
-
the next clause in the chain
2669 2670 2671 |
# File 'lib/syntax_tree/node.rb', line 2669 def consequent @consequent end |
#keyword ⇒ Object (readonly)
- Kw
-
the keyword that opens this expression
2663 2664 2665 |
# File 'lib/syntax_tree/node.rb', line 2663 def keyword @keyword end |
#value ⇒ Object (readonly)
- nil | untyped
-
optional value being switched on
2666 2667 2668 |
# File 'lib/syntax_tree/node.rb', line 2666 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
2682 2683 2684 |
# File 'lib/syntax_tree/node.rb', line 2682 def accept(visitor) visitor.visit_case(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2686 2687 2688 |
# File 'lib/syntax_tree/node.rb', line 2686 def child_nodes [keyword, value, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
2692 2693 2694 2695 2696 2697 2698 2699 2700 |
# File 'lib/syntax_tree/node.rb', line 2692 def deconstruct_keys(_keys) { keyword: keyword, value: value, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 |
# File 'lib/syntax_tree/node.rb', line 2702 def format(q) q.group do q.format(keyword) if value q.text(" ") q.format(value) end q.breakable(force: true) q.format(consequent) q.breakable(force: true) q.text("end") end end |