Class: YARP::IfNode

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

Overview

Represents the use of the ‘if` keyword, either in the block form or the modifier form.

bar if foo
^^^^^^^^^^

if foo then bar end
^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(if_keyword_loc, predicate, statements, consequent, end_keyword_loc, location) ⇒ IfNode

def initialize: (if_keyword_loc: Location?, predicate: Node, statements: Node?, consequent: Node?, end_keyword_loc: Location?, location: Location) -> void



2954
2955
2956
2957
2958
2959
2960
2961
# File 'lib/yarp/node.rb', line 2954

def initialize(if_keyword_loc, predicate, statements, consequent, end_keyword_loc, location)
  @if_keyword_loc = if_keyword_loc
  @predicate = predicate
  @statements = statements
  @consequent = consequent
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Instance Attribute Details

#consequentObject (readonly)

attr_reader consequent: Node?



2948
2949
2950
# File 'lib/yarp/node.rb', line 2948

def consequent
  @consequent
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location?



2951
2952
2953
# File 'lib/yarp/node.rb', line 2951

def end_keyword_loc
  @end_keyword_loc
end

#if_keyword_locObject (readonly)

attr_reader if_keyword_loc: Location?



2939
2940
2941
# File 'lib/yarp/node.rb', line 2939

def if_keyword_loc
  @if_keyword_loc
end

#predicateObject (readonly)

attr_reader predicate: Node



2942
2943
2944
# File 'lib/yarp/node.rb', line 2942

def predicate
  @predicate
end

#statementsObject (readonly)

attr_reader statements: Node?



2945
2946
2947
# File 'lib/yarp/node.rb', line 2945

def statements
  @statements
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



2964
2965
2966
# File 'lib/yarp/node.rb', line 2964

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

#child_nodesObject Also known as: deconstruct

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



2973
2974
2975
# File 'lib/yarp/node.rb', line 2973

def child_nodes
  [predicate, statements, consequent]
end

#deconstruct_keys(keys) ⇒ Object

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



2981
2982
2983
# File 'lib/yarp/node.rb', line 2981

def deconstruct_keys(keys)
  { if_keyword_loc: if_keyword_loc, predicate: predicate, statements: statements, consequent: consequent, end_keyword_loc: end_keyword_loc, location: location }
end

#end_keywordObject

def end_keyword: () -> String?



2991
2992
2993
# File 'lib/yarp/node.rb', line 2991

def end_keyword
  end_keyword_loc&.slice
end

#if_keywordObject

def if_keyword: () -> String?



2986
2987
2988
# File 'lib/yarp/node.rb', line 2986

def if_keyword
  if_keyword_loc&.slice
end

#set_newline_flag(newline_marked) ⇒ Object



2968
2969
2970
# File 'lib/yarp/node.rb', line 2968

def set_newline_flag(newline_marked)
  predicate.set_newline_flag(newline_marked)
end