class SyntaxTree::Case
Case
represents the beginning of a case chain.
case value when 1 "one" when 2 "two" else "number" end
Attributes
Kw
-
the keyword that opens this expression
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 3147 def initialize(keyword:, value:, consequent:, location:) @keyword = keyword @value = value @consequent = consequent @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 3205 def ===(other) other.is_a?(Case) && keyword === other.keyword && value === other.value && consequent === other.consequent end
Source
# File lib/syntax_tree/node.rb, line 3155 def accept(visitor) visitor.visit_case(self) end
Source
# File lib/syntax_tree/node.rb, line 3159 def child_nodes [keyword, value, consequent] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 3163 def copy(keyword: nil, value: nil, consequent: nil, location: nil) node = Case.new( keyword: keyword || self.keyword, value: value || self.value, consequent: consequent || self.consequent, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
Source
# File lib/syntax_tree/node.rb, line 3178 def deconstruct_keys(_keys) { keyword: keyword, value: value, consequent: consequent, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 3188 def format(q) q.group do q.format(keyword) if value q.text(" ") q.format(value) end q.breakable_force q.format(consequent) q.breakable_force q.text("end") end end