Class: YARP::ForNode

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

Overview

Represents the use of the ‘for` keyword.

for i in a end
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location) ⇒ ForNode

def initialize: (index: Node, collection: Node, statements: Node?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location, location: Location) -> void



2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
# File 'lib/yarp/node.rb', line 2450

def initialize(index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc, location)
  @index = index
  @collection = collection
  @statements = statements
  @for_keyword_loc = for_keyword_loc
  @in_keyword_loc = in_keyword_loc
  @do_keyword_loc = do_keyword_loc
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Instance Attribute Details

#collectionObject (readonly)

attr_reader collection: Node



2432
2433
2434
# File 'lib/yarp/node.rb', line 2432

def collection
  @collection
end

#do_keyword_locObject (readonly)

attr_reader do_keyword_loc: Location?



2444
2445
2446
# File 'lib/yarp/node.rb', line 2444

def do_keyword_loc
  @do_keyword_loc
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



2447
2448
2449
# File 'lib/yarp/node.rb', line 2447

def end_keyword_loc
  @end_keyword_loc
end

#for_keyword_locObject (readonly)

attr_reader for_keyword_loc: Location



2438
2439
2440
# File 'lib/yarp/node.rb', line 2438

def for_keyword_loc
  @for_keyword_loc
end

#in_keyword_locObject (readonly)

attr_reader in_keyword_loc: Location



2441
2442
2443
# File 'lib/yarp/node.rb', line 2441

def in_keyword_loc
  @in_keyword_loc
end

#indexObject (readonly)

attr_reader index: Node



2429
2430
2431
# File 'lib/yarp/node.rb', line 2429

def index
  @index
end

#statementsObject (readonly)

attr_reader statements: Node?



2435
2436
2437
# File 'lib/yarp/node.rb', line 2435

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2462
2463
2464
# File 'lib/yarp/node.rb', line 2462

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

#child_nodesObject Also known as: deconstruct

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



2467
2468
2469
# File 'lib/yarp/node.rb', line 2467

def child_nodes
  [index, collection, statements]
end

#deconstruct_keys(keys) ⇒ Object

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



2475
2476
2477
# File 'lib/yarp/node.rb', line 2475

def deconstruct_keys(keys)
  { index: index, collection: collection, statements: statements, for_keyword_loc: for_keyword_loc, in_keyword_loc: in_keyword_loc, do_keyword_loc: do_keyword_loc, end_keyword_loc: end_keyword_loc, location: location }
end

#do_keywordObject

def do_keyword: () -> String?



2490
2491
2492
# File 'lib/yarp/node.rb', line 2490

def do_keyword
  do_keyword_loc&.slice
end

#end_keywordObject

def end_keyword: () -> String



2495
2496
2497
# File 'lib/yarp/node.rb', line 2495

def end_keyword
  end_keyword_loc.slice
end

#for_keywordObject

def for_keyword: () -> String



2480
2481
2482
# File 'lib/yarp/node.rb', line 2480

def for_keyword
  for_keyword_loc.slice
end

#in_keywordObject

def in_keyword: () -> String



2485
2486
2487
# File 'lib/yarp/node.rb', line 2485

def in_keyword
  in_keyword_loc.slice
end