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.
37c332966b49eeb1d54eeefd3bc5ce97?d=identicon&s=25 dcorbin (Guest)
on 2005-11-26 19: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
7cf9493614c47ce48f8a56407a050085?d=identicon&s=25 mrkode (Guest)
on 2005-11-26 19:27
(Received via mailing list)
On 11/26/05, David Corbin <dcorbin@machturtle.com> 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.
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 chneukirchen (Guest)
on 2005-11-26 19:31
(Received via mailing list)
David Corbin <dcorbin@machturtle.com> 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].
5da4c52f43677f395aff5bde775593c2?d=identicon&s=25 Daniel Schierbeck (dasch)
on 2005-11-26 22:33
(Received via mailing list)
Christian Neukirchen wrote:
>> David
That doesn't really look much clearer to me...


Cheers,
Daniel
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2005-11-26 22:33
(Received via mailing list)
On Nov 26, 2005, at 2:52 PM, Daniel Schierbeck wrote:

>
> That doesn't really look much clearer to me...

Array( foo )

Same effect.

James Edward Gray II
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 chneukirchen (Guest)
on 2005-11-26 22:49
(Received via mailing list)
Daniel Schierbeck <daniel.schierbeck@gmail.com> writes:

> That doesn't really look much clearer to me...
But it doesn't hurt duck-typing.
45196398e9685000d195ec626d477f0e?d=identicon&s=25 transfire (Guest)
on 2005-11-26 23:29
(Received via mailing list)
> Array( foo )

  Array[ foo ]

T.
22b74ae3adfc74ff5c7c0b0a94b78a48?d=identicon&s=25 kozlov.y (Guest)
on 2005-11-27 08: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>
E4c257f62bf56e9076d2df2245ae8153?d=identicon&s=25 markus (Guest)
on 2005-11-27 13: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.