Class: YARP::InNode

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

Overview

Represents the use of the ‘in` keyword in a case statement.

case a; in b then c end
        ^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, statements, in_loc, then_loc, location) ⇒ InNode

def initialize: (pattern: Node, statements: Node?, in_loc: Location, then_loc: Location?, location: Location) -> void



3056
3057
3058
3059
3060
3061
3062
# File 'lib/yarp/node.rb', line 3056

def initialize(pattern, statements, in_loc, then_loc, location)
  @pattern = pattern
  @statements = statements
  @in_loc = in_loc
  @then_loc = then_loc
  @location = location
end

Instance Attribute Details

#in_locObject (readonly)

attr_reader in_loc: Location



3050
3051
3052
# File 'lib/yarp/node.rb', line 3050

def in_loc
  @in_loc
end

#patternObject (readonly)

attr_reader pattern: Node



3044
3045
3046
# File 'lib/yarp/node.rb', line 3044

def pattern
  @pattern
end

#statementsObject (readonly)

attr_reader statements: Node?



3047
3048
3049
# File 'lib/yarp/node.rb', line 3047

def statements
  @statements
end

#then_locObject (readonly)

attr_reader then_loc: Location?



3053
3054
3055
# File 'lib/yarp/node.rb', line 3053

def then_loc
  @then_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3065
3066
3067
# File 'lib/yarp/node.rb', line 3065

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

#child_nodesObject Also known as: deconstruct

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



3070
3071
3072
# File 'lib/yarp/node.rb', line 3070

def child_nodes
  [pattern, statements]
end

#deconstruct_keys(keys) ⇒ Object

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



3078
3079
3080
# File 'lib/yarp/node.rb', line 3078

def deconstruct_keys(keys)
  { pattern: pattern, statements: statements, in_loc: in_loc, then_loc: then_loc, location: location }
end

#inObject

def in: () -> String



3083
3084
3085
# File 'lib/yarp/node.rb', line 3083

def in
  in_loc.slice
end

#thenObject

def then: () -> String?



3088
3089
3090
# File 'lib/yarp/node.rb', line 3088

def then
  then_loc&.slice
end