Class: RedParse::IfOpNode

Inherits:
RawOpNode show all
Includes:
KeywordOpNode
Defined in:
lib/redparse/node.rb,
lib/redparse/node.rb

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary

Attributes inherited from Node

#endline, #errors, #offset, #parent, #startline

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Instance Method Summary collapse

Methods included from KeywordOpNode

#unparse

Methods inherited from RawOpNode

create, #image, #raw_unparse

Methods inherited from ValueNode

#lvalue

Methods inherited from Node

#+, #+@, #==, [], #[]=, #add_parent_links!, #begin_parsetree, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #image, #initialize_ivars, inline_symbols, #inspect, #lhs_unparse, #linerange, #lvalue, #lvars_defined_in, #merge_replacement_session, namelist, #negate, #original_brackets_assign, param_names, #parsetrees, #pretty_print, #prohibit_fixup, #replace_ivars_and_self, #replace_value, #rescue_parsetree, #to_parsetree, #to_parsetree_and_warnings, #unary, #walk, #xform_tree!

Methods included from Stackable::Meta

#build_exemplars, #enumerate_exemplars, #identity_param

Methods included from FlattenedIvars

#flattened_ivars, #flattened_ivars_equal?

Methods included from Stackable

#identity_name

Constructor Details

#initialize(left, op, right = nil) ⇒ IfOpNode

Returns a new instance of IfOpNode.



2857
2858
2859
2860
2861
2862
2863
2864
# File 'lib/redparse/node.rb', line 2857

def initialize(left,op,right=nil)
  op,right=nil,op unless right
  op=op.ident if op.respond_to? :ident
  @reverse=false
  @loop=false
  replace [left,right]
  condition.special_conditions! if condition.respond_to? :special_conditions!
end

Instance Method Details

#conditionObject



2855
# File 'lib/redparse/node.rb', line 2855

def condition; right end

#consequentObject



2856
# File 'lib/redparse/node.rb', line 2856

def consequent; left end

#elseObject



2868
# File 'lib/redparse/node.rb', line 2868

def else; nil end

#elsifsObject



2869
# File 'lib/redparse/node.rb', line 2869

def elsifs; [] end

#ifObject



2866
# File 'lib/redparse/node.rb', line 2866

def if; condition end

#opObject



2870
# File 'lib/redparse/node.rb', line 2870

def op; "if" end

#parsetree(o) ⇒ Object



2872
2873
2874
2875
2876
2877
2878
2879
2880
# File 'lib/redparse/node.rb', line 2872

def parsetree(o)
  cond=condition.rescue_parsetree(o)
  actions=[consequent.parsetree(o), nil]
  if cond.first==:not
    actions.reverse!
    cond=cond.last
  end
  [:if, cond, *actions]
end

#thenObject



2867
# File 'lib/redparse/node.rb', line 2867

def then; consequent end