module Alda::Sequence::RefineFlatten

Using this module can fix a bug of Array#flatten.

def (a = Object.new).method_missing(...)
  Object.new
end
[a].flatten rescue $! # => #<TypeError:...>
using Alda::Sequence::RefineFlatten
[a].flatten # => [#<Object:...>]

Public Instance Methods

flatten() click to toggle source

Overrides Array#flatten.

# File lib/alda-rb/event.rb, line 1130
def flatten
  each_with_object [] do |element, result|
    if element.is_a? Array
      result.push *element.flatten
    else
      result.push element
    end
  end
end