Method: Opal::Rewriters::PatternMatching::PatternConverter#on_array_pattern

Defined in:
lib/opal/rewriters/pattern_matching.rb

#on_array_pattern(node, tail = false) ⇒ Object

[0, 1, 2] or [*, 0, 1] or [0, 1, *]



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/opal/rewriters/pattern_matching.rb', line 197

def on_array_pattern(node, tail = false)
  children = *node
  children << s(:match_rest) if tail

  fixed_size = true
  array_size = 0

  children = children.each do |i|
    case i.type
    when :match_rest
      fixed_size = false
    else
      array_size += 1
    end
  end

  array(
    s(:sym, :array),
    to_ast(fixed_size),
    to_ast(array_size),
    to_ast(children.map(&method(:process)))
  )
end