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



1064
1065
1066
1067
1068
1069
1070
1071
# File 'lib/yarp/node.rb', line 1064

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



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

def case_keyword_loc
  @case_keyword_loc
end

#conditionsObject (readonly)

attr_reader conditions: Array



1052
1053
1054
# File 'lib/yarp/node.rb', line 1052

def conditions
  @conditions
end

#consequentObject (readonly)

attr_reader consequent: Node?



1055
1056
1057
# File 'lib/yarp/node.rb', line 1055

def consequent
  @consequent
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



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

def end_keyword_loc
  @end_keyword_loc
end

#predicateObject (readonly)

attr_reader predicate: Node?



1049
1050
1051
# File 'lib/yarp/node.rb', line 1049

def predicate
  @predicate
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1074
1075
1076
# File 'lib/yarp/node.rb', line 1074

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

#case_keywordObject

def case_keyword: () -> String



1092
1093
1094
# File 'lib/yarp/node.rb', line 1092

def case_keyword
  case_keyword_loc.slice
end

#child_nodesObject Also known as: deconstruct

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



1079
1080
1081
# File 'lib/yarp/node.rb', line 1079

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]



1087
1088
1089
# File 'lib/yarp/node.rb', line 1087

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



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

def end_keyword
  end_keyword_loc.slice
end