Bill Kelly
7/25/2007 7:32:00 PM
From: "Phlip" <phlip2005@gmail.com>
>
> 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?
Maybe:
irb(main):065:0> x = *[1,2,3]
=> [1, 2, 3]
irb(main):066:0> x = *[1]
=> 1
irb(main):067:0> x = *[]
=> nil
Regards,
Bill