G
Gennady Bystritksy
Hi, rubyists
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.
In other words:
in 1.6 [ *nil ] -> []
in 1.8 [ *nil ] -> [ nil ]
Was this incompatibility introduced deliberately or is it a bug that
slipped through?
It becomes a problem (or rather inconvenience) in 1.8, as I cannot
replace [ *o ] with o.to_a as in 1.6, because ruby 1.8 gives warning
"default `to_a' will be obsolete" for instances of user defined classes.
Thanks in advance,
Gennady.
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.
In other words:
in 1.6 [ *nil ] -> []
in 1.8 [ *nil ] -> [ nil ]
Was this incompatibility introduced deliberately or is it a bug that
slipped through?
It becomes a problem (or rather inconvenience) in 1.8, as I cannot
replace [ *o ] with o.to_a as in 1.6, because ruby 1.8 gives warning
"default `to_a' will be obsolete" for instances of user defined classes.
Thanks in advance,
Gennady.