From: dblack@... Date: 2007-07-26T06:56:40+09:00 Subject: Re: opposite of [thing].flatten Hi -- On Thu, 26 Jul 2007, Phlip wrote: > Gregory Brown wrote: > >>>> Array([["foo"]]) >> => [["foo"]] >> >> It does not accidentally flatten nested arrays, and does not throw a >> warning like Object#to_a does > > Ruby is a strongly-typed language that permits you to write interfaces that > are as feebly- or strongly-typed (or statically-typed) as you like. > > If your interface permits one item or a series of similar items, then those > nested arrays are not "accidentally" flattened, they are deliberately > pushed into your interface's contract. There are certainly cases where the flattening is not accidental, but it sounds like those aren't the ones Greg was referring to :-) It's really just a question of flattening being greedy and a bit of a "gotcha" at times. In any case, 1.9 introduces an argument to flatten, so one can do: array.flatten(1) and not have to worry about it. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)