flatten!(...)
public
Flattens self in place. Returns nil if no modifications
were made (i.e., array contains no subarrays.) If the optional
level argument determines the level of recursion to flatten.
a = [ 1, 2, [3, [4, 5] ] ]
a.flatten!
a.flatten!
a
a = [ 1, 2, [3, [4, 5] ] ]
a.flatten!(1)
Show source
/*
* call-seq:
* array.flatten! -> array or nil
* array.flatten!(level) -> array or nil
*
* Flattens _self_ in place.
* Returns <code>nil</code> if no modifications were made (i.e.,
* <i>array</i> contains no subarrays.) If the optional <i>level</i>
* argument determines the level of recursion to flatten.
*
* a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten!
* a.flatten!
* a
* a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten!(1)
*/
static VALUE
rb_ary_flatten_bang(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
{
int mod = 0, level = -1;
VALUE result, lv;
rb_scan_args(argc, argv, "01", &lv);
if (!NIL_P(lv)) level = NUM2INT(lv);
if (level == 0) return ary;
result = flatten(ary, level, &mod);
if (mod == 0) return Qnil;
rb_ary_replace(ary, result);
return ary;
}