Class: Rubinius::AST::When
- Defined in:
- lib/compiler/ast/control_flow.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#single ⇒ Object
Returns the value of attribute single.
-
#splat ⇒ Object
Returns the value of attribute splat.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(line, conditions, body) ⇒ When
constructor
A new instance of When.
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(line, conditions, body) ⇒ When
Returns a new instance of When.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/compiler/ast/control_flow.rb', line 45 def initialize(line, conditions, body) @line = line @body = body || NilLiteral.new(line) @splat = nil @single = nil if conditions.kind_of? ConcatArgs @splat = SplatWhen.new line, conditions.rest conditions = conditions.array end if conditions.kind_of? ArrayLiteral if conditions.body.last.kind_of? When last = conditions.body.pop if last.conditions.kind_of? ArrayLiteral conditions.body.concat last.conditions.body elsif last.single @splat = SplatWhen.new line, last.single else @splat = SplatWhen.new line, last.conditions end end if conditions.body.size == 1 and !@splat @single = conditions.body.first else @conditions = conditions end elsif conditions.kind_of? SplatValue @splat = SplatWhen.new line, conditions.value @conditions = nil else @conditions = conditions end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
43 44 45 |
# File 'lib/compiler/ast/control_flow.rb', line 43 def body @body end |
#conditions ⇒ Object
Returns the value of attribute conditions.
43 44 45 |
# File 'lib/compiler/ast/control_flow.rb', line 43 def conditions @conditions end |
#single ⇒ Object
Returns the value of attribute single.
43 44 45 |
# File 'lib/compiler/ast/control_flow.rb', line 43 def single @single end |
#splat ⇒ Object
Returns the value of attribute splat.
43 44 45 |
# File 'lib/compiler/ast/control_flow.rb', line 43 def splat @splat end |
Instance Method Details
#to_sexp ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/compiler/ast/control_flow.rb', line 81 def to_sexp if @single conditions_sexp = [:array, @single.to_sexp] else conditions_sexp = @conditions.to_sexp conditions_sexp << @splat.to_sexp if @splat end [:when, conditions_sexp, @body.to_sexp] end |