Sha256: 5565d74dbaa5b9670438448c21a268f282d52d9f583e430dcea6ae72ce041300

Contents?: true

Size: 178 Bytes

Versions: 10

Compression:

Stored size: 178 Bytes

Contents

class Array
  def flatten_once
    inject([]) { |result, elem| elem.is_a?(Array) ? result + elem : result << elem }
  end

  def flatten_once!
    replace(flatten_once)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
adva-core-0.0.14 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.13 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.9 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.8 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.7 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.6 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.5 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.4 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.2 lib/core_ext/ruby/array/flatten_once.rb
adva-core-0.0.1 lib/core_ext/ruby/array/flatten_once.rb