Gennady
1/8/2005 8:18:00 AM
Hi, Pit
I have checked that Array(nil) works fine both in 1.6 and 1.8, thanks
for the tip. Nevertheless, [ *o ] feels so much more attractive ;-).
And I still do not see the reason for the behavior being changed. Is
there any?
Thank you very much,
Gennady.
On Jan 7, 2005, at 10:32 PM, Pit Capitain wrote:
> Gennady Bystritksy schrieb:
>> In ruby 1.6 I use the following quite often to quickly convert to
>> arrays:
>> a = [ *o ]
>> If 'o' is already an array, 'a' will be the same. If 'o' is non-nil,
>> 'a' becomes an array with 'o' as a single element. Otherwise, if 'o'
>> is nil, 'a' becomes an empty array. Nice and clean.
>> However, in 1.8 if 'o' is nil, 'a' becomes an array with a single
>> element nil.
>
> Hi Gennady,
>
> you can use the method "Array":
>
> p Array( [ 1, 2, 3, ] )
> p Array( "x" )
> p Array( nil )
>
> results in
>
> [1, 2, 3]
> ["x"]
> []
>
> Regards,
> Pit
>
>
Sincerely,
Gennady Bystritsky