Click to See Complete Forum and Search --> : Ruby Help


debiandude
08-25-2002, 10:56 AM
Im trying to work with ruby. It seems pretty cool so far, but I am having a little trouble.

Let say I have a string "ABCDE" and I want it to print out the ascii number values of it like 65,66 etc.

I do this and it works:

test = "ABCDEF"

for i in 0 ... test.length
puts test[i].to_i
end


But I figured I could also use the each method, but that doesn't seem to work:



test = "ABCDEFG"

test.each { |i|
puts i.to_i
}


Could anyone explain why. Thanks.

Gnu/Vince
10-11-2002, 02:06 PM
Try this:


test = "ABCDEF"
test.each_byte { |b| puts b }

debiandude
10-12-2002, 04:21 PM
Wow if it wasn't for that email thing I don't think i would have every seen this. If been gone for a while from LNO, seems kinda wierd, when did they chnage the BB system?

Oh and thanks Gnu/Vince, I did eventually find that out on my own. Ruby is pretty cool.