D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
flatten-i.ri
back
Copy
U:RDoc::AnyMethod[iI"flatten:ETI"Array#flatten;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"BReturns a new array that is a recursive flattening of +self+ ;TI"%to +depth+ levels of recursion; ;TI"+depth+ must be an ;TI"a{integer-convertible object}[rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects] ;TI"or +nil+. ;TI" At each level of recursion:;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"2Each element that is an array is "flattened" ;TI":(that is, replaced by its individual array elements).;To;;0; [o; ; [I"4Each element that is not an array is unchanged ;TI"K(even if the element is an object that has instance method +flatten+).;T@o; ; [I"]With non-negative integer argument +depth+, flattens recursively through +depth+ levels:;T@o:RDoc::Markup::Verbatim; [I"?a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ] ;TI"Ka # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Ka.flatten(0) # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Ia.flatten(1 ) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Ia.flatten(1.1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Ga.flatten(2) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Ga.flatten(3) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;T:@format0o; ; [I"9With +nil+ or negative +depth+, flattens all levels.;T@o;; [I"Fa.flatten # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;TI"Fa.flatten(-1) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] ;T;0o; ; [I"Related: Array#flatten!; ;TI"Nsee also {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"'flatten(depth = nil) -> new_array ;T0[ I"(*args);T@9FI" Array;TcRDoc::NormalClass00