I did take a look in the problem:

static VALUE
rb_ary_flatten(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);
   OBJ_INFECT(result, ary);

   return result;
}

In the line
  if (level == 0) return ary;
you will get the reference to the original array, instead of
a reference to a clone.
The problem is: this is a bug or a feature? =D
That is, what is the behavior that we want when calling
flatten with 0, since this call doesn't make much sense.
It is easy to fix it, but I don't know if I should. If you guys
think it is a good idea, that I can take some time to do that.
Bye!

Rafael Schouery
VidaGeek.net



On Wed, Apr 8, 2009 at 8:01 PM, Paul Lewis <redmine / ruby-lang.org> wrote:
> Bug #1367: flatten(0) is not consistent with flatten(), flatten(1), etc.
> http://redmine.ruby-lang.org/issues/show/1367
>
> Author: Paul Lewis
> Status: Open, Priority: Normal
> Category: core
> ruby -v: ruby 1.9.0 (2008-06-20 revision 17482) [i486-linux]
>
>> a = [1, 2]
>> a2 = a.flatten
>> a2 << :a
>> a2
> => [1, 2, :a]
>> a
> => [1, 2]
>
>> b = [3, 4]
>> b2 = b.flatten 1
>> b2 << :b
>> b2
> => [3, 4, :b]
>> b
> => [3, 4]
>
> HOWEVER:
>
>> c = [5, 6]
>> c2 = c.flatten 0
>> c2 << :c
>> c2
> => [5, 6, :c]
>> c
> => [5, 6, :c]  <-- Huh?  Should be [5, 6].
>
>
> ----------------------------------------
> http://redmine.ruby-lang.org
>
>