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

Pages: 1-

Ruby N00by

Name: Anonymous 2010-04-25 21:40

What is wrong here?

puts 'What is your favourite number?'
fav_number = gets.chomp
better_number = fav_number.to_i + 1
puts 'A better favourite number would be, ' +better_number+ '!'

Name: Anonymous 2010-04-25 21:41

It's Ruby.

Name: Anonymous 2010-04-25 21:42

Anon here. how do I paste code on a thread and have it not format like everyone else's?

Name: Anonymous 2010-04-25 21:48

>>3
use sage, then use /prog/scrape.

>>1
use .to_s

Name: Anonymous 2010-04-25 21:57

>>4

if i use .to_s than i would get an errot because you cannot add a str. and an int.
:/ I'm new so prove me wrong :D

Name: Anonymous 2010-04-25 21:58


(princ "What is your favourite number?")
(format t "A better favourite number would be, ~A" (1+ (read)))

Name: Anonymous 2010-04-25 22:00

puts 'A better favourite number would be, ' +better_number.to_s+ '!'
ruby is dinamyc type but strict type you need convertion type date to other type date expliciti

Name: >>6 2010-04-25 22:03

Erm, I meant:

(format t "What is your favourite number?~%A better favourite number would be, ~A" (1+ (read)))

Name: Anonymous 2010-04-25 22:32

>>5
no, you wouldn't. you're getting an error because you're already trying to add a string and an int. use .to_s to convert the string to an int so you can just concatenate the three strings together.

and FOR FUCKS SAKE, LEARN TO USE FUCKING SAGE, YOU FUCKING ASSHOLE.

Name: Anonymous 2010-04-25 22:34

>>9
s/a (string) to an (int)/an \2 to a \1/

Name: Anonymous 2010-04-26 2:46

>>8
No, it might actually be a good idea to display the prompt before you try to read the answer. HIBT?

Name: Anonymous 2010-04-26 2:55

>>3
Don't bother with the outdated monospace paradigm.
Variable-width for ruby code listings is the standard.[1]

REFERENCES                     
1: The Pragmatic Bookshelf <http://pragprog.com/>;

Name: Anonymous 2010-04-26 3:07

how do I sage?

Name: Anonymous 2010-04-26 3:30

>>13
LOOK AT THE FUCKING NAME LINKS. HOW MUCH OF A FUCKING IDIOT DO YOU HAVE TO BE TO NOT FIGURE THAT OUT?

Name: Anonymous 2010-04-26 3:47

read your god damn interpreter output next time


puts 'What is your favourite number?'
fav_number = gets.chomp
better_number = fav_number.to_i + 1
puts "A better favourite number would be, #{better_number}!"

Name: Anonymous 2010-04-26 8:45

def method_missing(agile_dispatch)
  puts "what's you're favorite kind of bacon"
  gets
  puts "Mine is CHUNKY BACON ☆(≧ω≦)"
end

ask_whats_the_users_fave_bacon

Name: Anonymous 2010-04-26 17:24

Where's why_
I miss why_ ;_;
Why did why_ leave us alone?

Name: Anonymous 2010-04-27 0:16

<blockquote>
<code>
puts 'lotion on skin'
</code>
</blockquote>

Name: Anonymous 2010-04-27 1:54

>>18

else
   hose = gets

Name: Anonymous 2010-04-27 5:13

>>17
He went person_missing

Name: Anonymous 2010-04-27 7:09

>>19
gets(hose)?

Name: Anonymous 2010-04-27 8:31

>>21
Getters and setters considered harmful.

Name: Anonymous 2010-04-27 16:50

>>21
No, gets is like getLine.

Name: Anonymous 2010-04-28 12:51

gets == get string...

Name: Anonymous 2010-04-28 15:36

puts 'What is your favourite number?'
fav_number = gets.chomp.to_i
better_number = fav_number + 1
puts "A better favourite number would be '#{better_number}'!"

Name: Anonymous 2010-04-28 15:50

It's not real ruby unless it is as golfed as possible

puts "A better favorite number would be '#{gets.to_i + 1}'!"

Name: Anonymous 2010-04-28 17:03

>>26
puts"A better favorite number would be '#{gets.to_i+1}'!"

Name: Anonymous 2010-04-28 17:31

p"whats ur fav #";p"better:#{gets.to_i+1}"

Name: Anonymous 2010-04-28 17:50

This is the proper, idiomatic, and socially acceptable way of doing it:

# Provides a better number. See README.markdown for details.
# http://github.com/anoynmous/betternumber/tree/master/
#
# Author::    Anonymous  (sage@4chan.org)
# Copyright:: Copyright (c) 2010 Anonymous
# License::   MIT

require 'test/unit'

class Fixnum
  def better
    self + 1
  end
end

class TestBetterNumber < Test::Unit::TestCase
  def test_improvement
    assert_equal(2, 1.better)
    assert_equal(5, 4.better)
    assert_equal(48, 47.better)
    assert_equal(65536, 65535.better)
  end
end

Name: Anonymous 2010-04-28 18:13

>>29
socially acceptable
But you didn't post it on a blog.

Name: Anonymous 2010-04-28 18:52

>>30
No, that's OK, since all the ruby blogs are currently down because of Rails 3 alpha bugs, deployment issues, and undocumented features.

Name: Anonymous 2010-04-28 21:45

>>31
My BLOG was brought down by UNDOCUMENTED FEATURES!!!!!

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