Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3972

Re: Lets play a guessing game. (how to code this better?)

From Stu <stu@rubyprogrammer.net>
Newsgroups comp.lang.ruby
Subject Re: Lets play a guessing game. (how to code this better?)
Date 2011-05-05 02:28 -0500
Organization Service de news de lacave.net
Message-ID <BANLkTim-F1KCtdmSfjv6sij23cFSd04pkg@mail.gmail.com> (permalink)
References <60cd2d7685f4d805fa7b7b953b5667d5@ruby-forum.com>

Show all headers | View raw


Looks good. You don't need the extra call to_i where it is already an integer:

random = rand(100)
choice == random

Both expressions are fine without any castiing.

small nit pick. ruby is on my machine in /usr/local/bin ... to make
this portable use:

#!/usr/bin/env ruby

I suggest your next task is to break everything down to methods.  When
you get comfortable with the concept of methods make your user input
more strict as to only acquire a number.  You did a very good job,
Keep it going.

~Stu

On Thu, May 5, 2011 at 1:45 AM, Super Goat <ruby-forum@sgoat.33mail.com> wrote:
> I am a new Rubyist. I told my friend that I was learning Ruby. He asked
> me how that was going and then gave me a little challenge. His
> challenge, "Write a text game that guesses numbers 0-100". My reply,
> "you mean it picks a number at random, and you guess the number, it
> tells you higher or lower until you get it?". Up to this point I had not
> coded anything in Ruby on my own (aside from the examples in the book)
> and I saw this as a great first challenge. So here is what I got. It
> took me some time. I ran into trouble because I forgot to take into
> consideration the Class of the variables and couldn't figure out why the
> loops weren't working.
> My question to you all... how could I have done this better or do you
> seeing anything that is wrong.  Attached is the code. Thanks for the
> feedback.
>
> Attachments:
> http://www.ruby-forum.com/attachment/6168/100guess.rb
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Lets play a guessing game. (how to code this better?) Super Goat <ruby-forum@sgoat.33mail.com> - 2011-05-05 01:45 -0500
  Re: Lets play a guessing game. (how to code this better?) Stu <stu@rubyprogrammer.net> - 2011-05-05 02:28 -0500
  Re: Lets play a guessing game. (how to code this better?) Josh Cheek <josh.cheek@gmail.com> - 2011-05-05 02:51 -0500
  Re: Lets play a guessing game. (how to code this better?) John Feminella <johnf@bitsbuilder.com> - 2011-05-05 03:10 -0500
    Re: Lets play a guessing game. (how to code this better?) Johannes Held <johannes.held@informatik.uni-erlangen.de> - 2011-05-06 10:51 +0200
      Re: Lets play a guessing game. (how to code this better?) Johnny Morrice <spoon@killersmurf.com> - 2011-05-06 07:01 -0500
        Re: Lets play a guessing game. (how to code this better?) Johnny Morrice <spoon@killersmurf.com> - 2011-05-06 07:04 -0500
        Re: Lets play a guessing game. (how to code this better?) Johannes Held <johannes.held@informatik.uni-erlangen.de> - 2011-05-06 14:13 +0200
          Re: Lets play a guessing game. (how to code this better?) Johnny Morrice <spoon@killersmurf.com> - 2011-05-06 07:23 -0500
  Re: Lets play a guessing game. (how to code this better?) Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-05-05 03:56 -0500
  Re: Lets play a guessing game. (how to code this better?) Martin Boese <boesemar@gmx.de> - 2011-05-05 10:32 -0500
  Re: Lets play a guessing game. (how to code this better?) Super Goat <ruby-forum@sgoat.33mail.com> - 2011-05-06 01:18 -0500
    Re: Lets play a guessing game. (how to code this better?) Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-05-06 02:27 -0500
    Re: Lets play a guessing game. (how to code this better?) Josh Cheek <josh.cheek@gmail.com> - 2011-05-06 02:34 -0500
  Re: Lets play a guessing game. (how to code this better?) Super Goat <ruby-forum@sgoat.33mail.com> - 2011-05-08 00:08 -0500
    Re: Lets play a guessing game. (how to code this better?) Josh Cheek <josh.cheek@gmail.com> - 2011-05-08 00:30 -0500
    Re: Lets play a guessing game. (how to code this better?) Stu <stu@rubyprogrammer.net> - 2011-05-08 01:16 -0500
      Re: Lets play a guessing game. (how to code this better?) Stu <stu@rubyprogrammer.net> - 2011-05-08 02:22 -0500
        Re: Lets play a guessing game. (how to code this better?) Super Goat <ruby-forum@sgoat.33mail.com> - 2011-05-08 21:20 -0500
          Re: Lets play a guessing game. (how to code this better?) Stu <stu@rubyprogrammer.net> - 2011-05-09 00:29 -0500

csiph-web