Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/ruby/array/flatten_once.rb

Instance Method Summary collapse

Instance Method Details

#flatten_onceObject



2
3
4
# File 'lib/core_ext/ruby/array/flatten_once.rb', line 2

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

#flatten_once!Object



6
7
8
# File 'lib/core_ext/ruby/array/flatten_once.rb', line 6

def flatten_once!
  replace(flatten_once)
end