Forum: Ruby warning: default `to_a' will be obsolete

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dcorbin (Guest)
on 2005-11-26 20:11
(Received via mailing list)
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
mrkode (Guest)
on 2005-11-26 20:27
(Received via mailing list)
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.
chneukirchen (Guest)
on 2005-11-26 20:31
(Received via mailing list)
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].
Daniel S. (Guest)
on 2005-11-26 23:33
(Received via mailing list)
Christian N. wrote:
>> David
That doesn't really look much clearer to me...


Cheers,
Daniel
James G. (Guest)
on 2005-11-26 23:33
(Received via mailing list)
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
chneukirchen (Guest)
on 2005-11-26 23:49
(Received via mailing list)
Daniel S. <removed_email_address@domain.invalid> writes:

> That doesn't really look much clearer to me...
But it doesn't hurt duck-typing.
transfire (Guest)
on 2005-11-27 00:29
(Received via mailing list)
> Array( foo )

  Array[ foo ]

T.
kozlov.y (Guest)
on 2005-11-27 09:13
(Received via mailing list)
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>
markus (Guest)
on 2005-11-27 14:41
(Received via mailing list)
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
This topic is locked and can not be replied to.