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



3048
3049
3050
3051
3052
3053
3054
# File 'lib/yarp/node.rb', line 3048

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



3042
3043
3044
# File 'lib/yarp/node.rb', line 3042

def in_loc
  @in_loc
end

#patternObject (readonly)

attr_reader pattern: Node



3036
3037
3038
# File 'lib/yarp/node.rb', line 3036

def pattern
  @pattern
end

#statementsObject (readonly)

attr_reader statements: Node?



3039
3040
3041
# File 'lib/yarp/node.rb', line 3039

def statements
  @statements
end

#then_locObject (readonly)

attr_reader then_loc: Location?



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

def then_loc
  @then_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3057
3058
3059
# File 'lib/yarp/node.rb', line 3057

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

#child_nodesObject Also known as: deconstruct

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



3063
3064
3065
# File 'lib/yarp/node.rb', line 3063

def child_nodes
  [pattern, statements]
end

#deconstruct_keys(keys) ⇒ Object

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



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

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

#inObject

def in: () -> String



3076
3077
3078
# File 'lib/yarp/node.rb', line 3076

def in
  in_loc.slice
end

#thenObject

def then: () -> String?



3081
3082
3083
# File 'lib/yarp/node.rb', line 3081

def then
  then_loc&.slice
end