To_a

Howdy, jewel hunters

  I've been working on the Credit Card problem, and am using the command .to_a to put my numbers into an array.

However, I get a warning everytime I do so:
#122_CreditCards.rb:45: warning: default `to_a' will be obsolete

What should I do instead of to_a?

-------------------------------------------------------|
~ Ari
crap my sig won't fit

Howdy, jewel hunters

        I've been working on the Credit Card problem, and am using the
command .to_a to put my numbers into an array.

However, I get a warning everytime I do so:
#122_CreditCards.rb:45: warning: default `to_a' will be obsolete

What should I do instead of to_a?

This depends on the content of line 45 of 122_CreditCards.rb :wink:
Would you mind sharing it (with some context lines) with us?

Cheers
Robert

···

On 5/10/07, Ari Brown <ari@aribrown.com> wrote:

-------------------------------------------------------|
~ Ari
crap my sig won't fit

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

Ruby currently implements Object#to_a, which just returns [self]:

  obj.to_a -> anArray

···

On 5/11/07, Ari Brown <ari@aribrown.com> wrote:

Howdy, jewel hunters

        I've been working on the Credit Card problem, and am using the
command .to_a to put my numbers into an array.

However, I get a warning everytime I do so:
#122_CreditCards.rb:45: warning: default `to_a' will be obsolete

What should I do instead of to_a?

------------------------------------------------------------------------
     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 you get the deprecation warning when you call to_a on an object of
a class that doesn't provide it, so that the implentation defaults to
Object#to_a.

Use [obj] instead:

a = 1

=> 1

a.to_a

(irb):2: warning: default `to_a' will be obsolete
=> [1]

[a]

=> [1]

martin

Ok, I seemed to have fixed it. .to_a works, but what I need was .split(//). I never knew until now that it puts it into an array for you!

···

On May 10, 2007, at 6:01 PM, Robert Dober wrote:

On 5/10/07, Ari Brown <ari@aribrown.com> wrote:

Howdy, jewel hunters

        I've been working on the Credit Card problem, and am using the
command .to_a to put my numbers into an array.

However, I get a warning everytime I do so:
#122_CreditCards.rb:45: warning: default `to_a' will be obsolete

What should I do instead of to_a?

This depends on the content of line 45 of 122_CreditCards.rb :wink:
Would you mind sharing it (with some context lines) with us?

-------------------------------------------------------|
~ Ari
crap my sig won't fit

Not exactly the same thing though, if you don't know that the obj
isn't already an array then there's no guarantee that

[obj] == obj.to_a

obj = 1
[obj] #=> [1]

obj = %{already an array}
[obj] #=> [['already', 'an', 'array']]

That's why the context is important in determining the actuall problem
being addressed.

···

On 5/11/07, Martin DeMello <martindemello@gmail.com> wrote:

On 5/11/07, Ari Brown <ari@aribrown.com> wrote:
> Howdy, jewel hunters
>
> I've been working on the Credit Card problem, and am using the
> command .to_a to put my numbers into an array.
>
> However, I get a warning everytime I do so:
> #122_CreditCards.rb:45: warning: default `to_a' will be obsolete
>
> What should I do instead of to_a?

Ruby currently implements Object#to_a, which just returns [self]:

  obj.to_a -> anArray
------------------------------------------------------------------------
     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 you get the deprecation warning when you call to_a on an object of
a class that doesn't provide it, so that the implentation defaults to
Object#to_a.

Use [obj] instead:

>> a = 1
=> 1
>> a.to_a
(irb):2: warning: default `to_a' will be obsolete
=> [1]
>> [a]
=> [1]

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

This is an email that will respond to all who are interested in my misdemeanor among rubists...

So you get the deprecation warning when you call to_a on an object of
a class that doesn't provide it, so that the implentation defaults to
Object#to_a.

Use [obj] instead:

Well that certainly seems to do the trick.

This is exactly what I did.

a = 1

=> 1

a.to_a

(irb):2: warning: default `to_a' will be obsolete
=> [1]

It produced an error, but I was unsure of what to make of it. I knew that it would be obsoletified, and I thought there was some enumerator function that most people did. I didn't, and still don't, know how to use enumerators in this, or what they can even be fully used for. Help?

Apparently .split(//) puts things into an array. Did you know that?!?! I didn't know that!!!

[a]

=> [1]

That's about five more things I just added to my ruby vocabulary :smiley:

--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.

···

On May 11, 2007, at 5:15 PM, Martin DeMello wrote:

Ari, warnings about deprecations are just that. Warnings. They ARE true. In the future these things will be removed and their replacements already exist. Sometimes they are just synonyms and sometimes they are actually different implementations. Any time you see such a warning just try to find the method that should be used instead ( ri is a good way to check this, there is usually some blurb telling you the alternative method.)
Generally, Matz is slow about completely removing that functionality to give time for people to change and refactor old code. But don't depend on it.

···

On May 11, 2007, at 7:04 AM, Ari Brown wrote:

Ok, I seemed to have fixed it. .to_a works, but what I need was .split(//). I never knew until now that it puts it into an array for you!

On May 10, 2007, at 6:01 PM, Robert Dober wrote:

On 5/10/07, Ari Brown <ari@aribrown.com> wrote:

Howdy, jewel hunters

        I've been working on the Credit Card problem, and am using the
command .to_a to put my numbers into an array.

However, I get a warning everytime I do so:
#122_CreditCards.rb:45: warning: default `to_a' will be obsolete

What should I do instead of to_a?

This depends on the content of line 45 of 122_CreditCards.rb :wink:
Would you mind sharing it (with some context lines) with us?

-------------------------------------------------------|
~ Ari
crap my sig won't fit

Ari,

You're still too mysterious about what you fixed. If you show the
line which caused the original problem, we might help you get a deeper
understanding of what's really going on.

···

On 5/10/07, Ari Brown <ari@aribrown.com> wrote:

Ok, I seemed to have fixed it. .to_a works, but what I need was .split
(//). I never knew until now that it puts it into an array for you!

On May 10, 2007, at 6:01 PM, Robert Dober wrote:

> This depends on the content of line 45 of 122_CreditCards.rb :wink:
> Would you mind sharing it (with some context lines) with us?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Hi --

···

On Sat, 12 May 2007, Rick DeNatale wrote:

On 5/11/07, Martin DeMello <martindemello@gmail.com> wrote:

On 5/11/07, Ari Brown <ari@aribrown.com> wrote:
> Howdy, jewel hunters
>
> I've been working on the Credit Card problem, and am using the
> command .to_a to put my numbers into an array.
>
> However, I get a warning everytime I do so:
> #122_CreditCards.rb:45: warning: default `to_a' will be obsolete
>
> What should I do instead of to_a?

Ruby currently implements Object#to_a, which just returns [self]:

  obj.to_a -> anArray
------------------------------------------------------------------------
     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 you get the deprecation warning when you call to_a on an object of
a class that doesn't provide it, so that the implentation defaults to
Object#to_a.

Use [obj] instead:

>> a = 1
=> 1
>> a.to_a
(irb):2: warning: default `to_a' will be obsolete
=> [1]
>> [a]
=> [1]

Not exactly the same thing though, if you don't know that the obj
isn't already an array then there's no guarantee that

[obj] == obj.to_a

obj = 1
[obj] #=> [1]

obj = %{already an array}
[obj] #=> [['already', 'an', 'array']]

That's why the context is important in determining the actuall problem
being addressed.

I think that the * operator will (always?) do it:

   [*1] # => [1]
   [obj] # => ["already", "an", "array"]

David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf\)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

Yep, as long as you actually USE it <G>
irb(main):001:0> obj = %w{already an array}
=> ["already", "an", "array"]
irb(main):002:0> [*obj]
=> ["already", "an", "array"]

I'm not sure whether or not the to_splat changes in Ruby 1.9 will have
a subtle effect on this though.

···

On 5/11/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

Hi --

On Sat, 12 May 2007, Rick DeNatale wrote:

>
> Not exactly the same thing though, if you don't know that the obj
> isn't already an array then there's no guarantee that
>
> [obj] == obj.to_a
>
> obj = 1
> [obj] #=> [1]
>
> obj = %{already an array}
> [obj] #=> [['already', 'an', 'array']]

I think that the * operator will (always?) do it:

   [*1] # => [1]
   [obj] # => ["already", "an", "array"]

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Hi --

Hi --

>
> Not exactly the same thing though, if you don't know that the obj
> isn't already an array then there's no guarantee that
>
> [obj] == obj.to_a
>
> obj = 1
> [obj] #=> [1]
>
> obj = %{already an array}
> [obj] #=> [['already', 'an', 'array']]

I think that the * operator will (always?) do it:

   [*1] # => [1]
   [obj] # => ["already", "an", "array"]

Yep, as long as you actually USE it <G>
irb(main):001:0> obj = %w{already an array}
=> ["already", "an", "array"]
irb(main):002:0> [*obj]
=> ["already", "an", "array"]

Whoops :slight_smile:

I'm not sure whether or not the to_splat changes in Ruby 1.9 will have
a subtle effect on this though.

I thought that was considered just an experiment... and I admit I had
sort of hoped that was the case. But if it does remain, it will
definitely make my answer obsolete.

David

···

On Sat, 12 May 2007, Rick DeNatale wrote:

On 5/11/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

On Sat, 12 May 2007, Rick DeNatale wrote:

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
    (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf\)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)