Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

basic shit that should work but doesn't

Name: Anonymous 2006-10-11 13:32

puts '12'.to_i + 12
puts '1234 qdasasjkdaklsj'.to_i
puts 12.to_s + 'asd'
puts 'lolhi.pick a number'
numb = gets.to_i
puts numb.chomp.to_s + 1 + 'is a better number, faggot'

SHOULD read

24
1234
lolhi.pick a number
[number]
([number]+1) is a better number, faggot.

Instead it reads

24
1234
lolhi.pick a number
[number]
sandbox.rb:7:in '+': String can't be coerced into Fixnum (TypeError) from sandbox.rb:7

Someone please tel me why this is a complete fialuer? to_i obviously works, but can I not use it on a string in a variable? If so, shit sucks.

Name: Anonymous 2006-10-12 3:38

Made the fucker work and realised I hadn't posted it here.

puts 'lolhi. pick a number'
fav = gets.to_i
puts (fav.to_s) + '?'
fav2 = fav+1
pits fav2.to_s ' is a prime number, faggot.'

I have no idea why chucking parenthesis around the first to_s made the prog run, but wtf ever works.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List