[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

strange result from to_a

paul.denize

4/10/2009 4:23:00 AM

I had unexpected results and could not figure out why

puts (" ".."~").to_a.inspect
returns results of " " thru "9"

m = []
(" "[0].."~"[0]).to_a.each{|c| m << c.chr}
puts m.inspect

Is a longwinded way of getting the samne but it gives all the results

" " thru "~"

Can anyone tell me why this is so?

I also hear that to_a is to be depricated - but it is hard to figure out
what the alternatives are. Everything I found gave the same unexpeted
results.

Paul
--
Posted via http://www.ruby-....

4 Answers

botp

4/10/2009 4:35:00 AM

0

On Fri, Apr 10, 2009 at 12:22 PM, Paul Denize <paul.denize@datacom.co.nz> wrote:
> I had unexpected results and could not figure out why
>
> puts (" ".."~").to_a.inspect
> returns results of " " thru "9"

works fine here, running ruby1.9

paul.denize

4/10/2009 5:20:00 AM

0

Ok, I'm on ruby 1.8.6
Might be time to upgrade.

Thanks
--
Posted via http://www.ruby-....

paul.denize

4/10/2009 5:32:00 AM

0

Yep, upgraded and the problem is gone.
--
Posted via http://www.ruby-....

Sebastian Hungerecker

4/10/2009 10:55:00 AM

0

Paul Denize wrote:
> puts (" ".."~").to_a.inspect
> returns results of " " thru "9"

That's because "9".succ is "10" instead of ":"

> I also hear that to_a is to be depricated - but it is hard to figure out
> what the alternatives are.

Only Object#to_a is deprecated.