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



2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
# File 'lib/yarp/node.rb', line 2430

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



2412
2413
2414
# File 'lib/yarp/node.rb', line 2412

def collection
  @collection
end

#do_keyword_locObject (readonly)

attr_reader do_keyword_loc: Location?



2424
2425
2426
# File 'lib/yarp/node.rb', line 2424

def do_keyword_loc
  @do_keyword_loc
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



2427
2428
2429
# File 'lib/yarp/node.rb', line 2427

def end_keyword_loc
  @end_keyword_loc
end

#for_keyword_locObject (readonly)

attr_reader for_keyword_loc: Location



2418
2419
2420
# File 'lib/yarp/node.rb', line 2418

def for_keyword_loc
  @for_keyword_loc
end

#in_keyword_locObject (readonly)

attr_reader in_keyword_loc: Location



2421
2422
2423
# File 'lib/yarp/node.rb', line 2421

def in_keyword_loc
  @in_keyword_loc
end

#indexObject (readonly)

attr_reader index: Node



2409
2410
2411
# File 'lib/yarp/node.rb', line 2409

def index
  @index
end

#statementsObject (readonly)

attr_reader statements: Node?



2415
2416
2417
# File 'lib/yarp/node.rb', line 2415

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



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

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

#child_nodesObject Also known as: deconstruct

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



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

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]



2456
2457
2458
# File 'lib/yarp/node.rb', line 2456

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?



2471
2472
2473
# File 'lib/yarp/node.rb', line 2471

def do_keyword
  do_keyword_loc&.slice
end

#end_keywordObject

def end_keyword: () -> String



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

def end_keyword
  end_keyword_loc.slice
end

#for_keywordObject

def for_keyword: () -> String



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

def for_keyword
  for_keyword_loc.slice
end

#in_keywordObject

def in_keyword: () -> String



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

def in_keyword
  in_keyword_loc.slice
end