Class: YARP::CaseNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of a case statement.

case true ^^^^^^^^^ when false end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location) ⇒ CaseNode

def initialize: (predicate: Node?, conditions: Array, consequent: Node?, case_keyword_loc: Location, end_keyword_loc: Location, location: Location) -> void



1073
1074
1075
1076
1077
1078
1079
1080
# File 'lib/yarp/node.rb', line 1073

def initialize(predicate, conditions, consequent, case_keyword_loc, end_keyword_loc, location)
  @predicate = predicate
  @conditions = conditions
  @consequent = consequent
  @case_keyword_loc = case_keyword_loc
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Instance Attribute Details

#case_keyword_locObject (readonly)

attr_reader case_keyword_loc: Location



1067
1068
1069
# File 'lib/yarp/node.rb', line 1067

def case_keyword_loc
  @case_keyword_loc
end

#conditionsObject (readonly)

attr_reader conditions: Array



1061
1062
1063
# File 'lib/yarp/node.rb', line 1061

def conditions
  @conditions
end

#consequentObject (readonly)

attr_reader consequent: Node?



1064
1065
1066
# File 'lib/yarp/node.rb', line 1064

def consequent
  @consequent
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



1070
1071
1072
# File 'lib/yarp/node.rb', line 1070

def end_keyword_loc
  @end_keyword_loc
end

#predicateObject (readonly)

attr_reader predicate: Node?



1058
1059
1060
# File 'lib/yarp/node.rb', line 1058

def predicate
  @predicate
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1083
1084
1085
# File 'lib/yarp/node.rb', line 1083

def accept(visitor)
  visitor.visit_case_node(self)
end

#case_keywordObject

def case_keyword: () -> String



1102
1103
1104
# File 'lib/yarp/node.rb', line 1102

def case_keyword
  case_keyword_loc.slice
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



1089
1090
1091
# File 'lib/yarp/node.rb', line 1089

def child_nodes
  [predicate, *conditions, consequent]
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



1097
1098
1099
# File 'lib/yarp/node.rb', line 1097

def deconstruct_keys(keys)
  { predicate: predicate, conditions: conditions, consequent: consequent, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc, location: location }
end

#end_keywordObject

def end_keyword: () -> String



1107
1108
1109
# File 'lib/yarp/node.rb', line 1107

def end_keyword
  end_keyword_loc.slice
end