strange result from to_a

P

Paul Denize

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
 
S

Sebastian Hungerecker

Paul said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top