Class: Melbourne::AST::When
- Defined in:
- lib/melbourne/ast/control_flow.rb
Overview
A when statement in a case statement as in:
case a
when 1 then
# something
when 2
# something
end
Instance Attribute Summary collapse
-
#body ⇒ Object
The body for the
whenstatement. -
#conditions ⇒ Object
The conditions for which the
whenstatement is true ornilif only a single value is specified. -
#single ⇒ Object
The single value for the
whenstatement if only a single value is specified,nilotherwise. -
#splat ⇒ Object
Any splat (+*something+) that is specified as a condition for the
whenstatement ornilof no splat is specified.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(line, conditions, body) ⇒ When
constructor
A new instance of When.
Methods inherited from Node
Constructor Details
#initialize(line, conditions, body) ⇒ When
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/melbourne/ast/control_flow.rb', line 83 def initialize(line, conditions, body) @line = line @body = body || Nil.new(line) @splat = nil @single = nil 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 else @conditions = conditions end end |
Instance Attribute Details
#body ⇒ Object
The body for the when statement
73 74 75 |
# File 'lib/melbourne/ast/control_flow.rb', line 73 def body @body end |
#conditions ⇒ Object
The conditions for which the when statement is true or nil if only a single value is specified
69 70 71 |
# File 'lib/melbourne/ast/control_flow.rb', line 69 def conditions @conditions end |
#single ⇒ Object
The single value for the when statement if only a single value is specified, nil otherwise
77 78 79 |
# File 'lib/melbourne/ast/control_flow.rb', line 77 def single @single end |
#splat ⇒ Object
Any splat (+*something+) that is specified as a condition for the when statement or nil of no splat is specified
81 82 83 |
# File 'lib/melbourne/ast/control_flow.rb', line 81 def splat @splat end |