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

Pages: 1-

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-11 13:35 (sage)

puts "#{numb + 1} is a prime, faggot"

Name: Anonymous 2006-10-11 14:13

Hmm... looks like my version of ruby is an unstable fucker. time to dl an older version.

Name: Anonymous 2006-10-11 14:19

I know shit all about ruby, but shouldn't you add 1 before converting the number to a string?

Name: Anonymous 2006-10-11 14:25

Hmm.

Yes, you're correct. BRAINFARTS FOR THE WIN!

New version:
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.'

Still doesn't fucking work. Stupid unstable shit version.

Name: Anonymous 2006-10-12 1:45

[b]puts[/b] fav2.to_s ' is a prime number, faggot.'Doesn't ruby give an error for this kind of stuff?

Name: Anonymous 2006-10-12 2:05

puts is one of the print methods, so no. You can use print, p, and puts, which stands for put string IIRC... and that's all I can think of off the top of my head.

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.

Name: Anonymous 2006-10-12 16:31

>>8
That's what happens when language syntax sucks, e.g. Perl, Ruby

Name: Anonymous 2009-01-14 14:20

VALID PERL CODE

Name: Trollbot9000 2009-07-01 8:49

Typeerror from sandbox rb 7 Someone please  tel me why  this is a  superiorated version of  this post on  my desk by  this time tomorrow?

Name: Sgt.KabuɅ殺kiman翿攢 2012-05-28 20:26

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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