Class: Estreet::SwitchStatement
- Defined in:
- lib/estreet/switch_statement.rb
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(discriminant, kases) ⇒ SwitchStatement
constructor
kases is an array of 2-element arrays, or 1 for the default case.
Methods inherited from Statement
Methods inherited from Node
Constructor Details
#initialize(discriminant, kases) ⇒ SwitchStatement
kases is an array of 2-element arrays, or 1 for the default case
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/estreet/switch_statement.rb', line 4 def initialize(discriminant, kases) @kases = kases.map do |kase| raise TypeError, "Invalid case: #{kase}" unless kase.is_a? Array case kase.length when 2 then SwitchCase.new(*kase) when 1 then SwitchCase.default(kase.first) else raise TypeError, "Invalid case: #{kase}" end end @discriminant = discriminant.to_expression end |
Instance Method Details
#attributes ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/estreet/switch_statement.rb', line 18 def attributes super.merge( discriminant: @discriminant, cases: @kases, lexical: false, # TODO: an ES6 thing? ) end |