[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Ari Brown

5/10/2007 9:51:00 PM

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


10 Answers

Robert Dober

5/10/2007 10:01:00 PM

0

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 ;)
Would you mind sharing it (with some context lines) with us?

Cheers
Robert
>
>
> -------------------------------------------------------|
> ~ 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

Ari Brown

5/10/2007 10:04:00 PM

0

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 ;)
> Would you mind sharing it (with some context lines) with us?

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



John Joyce

5/11/2007 3:03:00 AM

0


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 ;)
>> Would you mind sharing it (with some context lines) with us?
>
> -------------------------------------------------------|
> ~ Ari
> crap my sig won't fit
>
>
>
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.

Rick DeNatale

5/11/2007 8:16:00 PM

0

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 ;)
> > Would you mind sharing it (with some context lines) with us?

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.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Martin DeMello

5/11/2007 9:15:00 PM

0

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]

martin

Rick DeNatale

5/11/2007 10:17:00 PM

0

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.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

dblack

5/11/2007 10:36:00 PM

0

Rick DeNatale

5/11/2007 11:03:00 PM

0

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"]

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.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

dblack

5/11/2007 11:18:00 PM

0

Ari Brown

5/12/2007 1:59:00 AM

0

This is an email that will respond to all who are interested in my
misdemeanor among rubists...
On May 11, 2007, at 5:15 PM, Martin DeMello wrote:

> 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 :-D

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