Warning: default `to_a' will be obsolete


#1

I’m getting this warning, which I think is new in 1.8.3.

warning: default `to_a’ will be obsolete

However, I can’t find what the expected alternative is. Any pointers?

David


#2

On 11/26/05, David C. removed_email_address@domain.invalid wrote:

I’m getting this warning, which I think is new in 1.8.3.

warning: default `to_a’ will be obsolete

However, I can’t find what the expected alternative is. Any pointers?

David

Object#to_a from ri:

Returns an array representation of obj. For objects of class
+Object+ and others that don’t explicitly override the method, the
return value is an array containing +self+. However, this latter
behavior will soon be obsolete.

so it’s this “return array containing self” that’s going obsolete.


#3

David C. removed_email_address@domain.invalid writes:

I’m getting this warning, which I think is new in 1.8.3.

warning: default `to_a’ will be obsolete

However, I can’t find what the expected alternative is. Any pointers?

Use [*foo].


#4

Christian N. wrote:

David
That doesn’t really look much clearer to me…

Cheers,
Daniel


#5

Daniel S. removed_email_address@domain.invalid writes:

That doesn’t really look much clearer to me…
But it doesn’t hurt duck-typing.


#6

On Nov 26, 2005, at 2:52 PM, Daniel S. wrote:

That doesn’t really look much clearer to me…

Array( foo )

Same effect.

James Edward G. II


#7

and in the 1.9.0 it is already happens
irb(main):001:0> x = 1
=> 1
irb(main):002:0> x.to_a
NoMethodError: undefined method `to_a’ for 1:Fixnum
from (irb):2
irb(main):003:0>


#8

Array( foo )

Array[ foo ]

T.


#9

Trans wrote:

Array( foo )

Array[ foo ]

Not quite the same:

foo = [1, 2, 3]
Array(foo) => [1, 2, 3]
Array[foo] => [[1, 2, 3]]

Markus