From: Philip Hallstrom Date: 2007-07-26T04:27:18+09:00 Subject: Re: opposite of [thing].flatten > Ruby-ists: > > We all know this clever idiom to turn a variable that might be an Array into > one known to be an Array: > > thing = [thing].flatten > > That saves a lot of if statements to permit thing's type to overload. > > What is the opposite (clever) operation? How to turn a list of one item into > one item, and a list of zero items into nil, but pass thru the list of many > items? This almost gets there... irb(main):006:0> [[]].first => [] irb(main):007:0> [["one","two"]].first => ["one", "two"] irb(main):008:0> ["one"].first => "one"