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.
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.