Review a small Ruby Project

Hi,

I'm learning Ruby, i just done a small RubyGame to apply what i learned.
Can you review the project ? Im looking for best-practice, refactoring keeping the 3 classes usage.

The project is here : https://goo.gl/b1bRMK

Thank you very much.

/Nathan

Well the code is readable and all that even if it seems quite long for a
simple guess a number between X and Y type game. But presentation logic is
always a handful :slight_smile:

Anyhow just two little points.

The Core class is used to create the @player instance variable. 'Core' is a
pretty meaningless name, conveys nothing, less than even 'Utils'. It should
probably be called Player as that is what it is. Likewise the UserInterface
class is actually the game isn't it. Again the name is misleading.

In the UserInterface class the game loop is the play method which has a
loop with an explicit exit condition "result != 'a winner'". However there
is another exit, when getting the users input the program can bail if the
user inputs 'quit'.

To be honest I would have ask() pass back the 'quit' and handle things a
little differently. Have the loop allow the user to quit normally, one
point of control. ​Having an explicit flow control, the while loop, but
hiding other flow control in another function, which is not even directly
called in the loop, is a very bad habit.

The set_name function uses ask so if the user input 'quit' as the name then
ask would bail the whole application, the "try_a_name == 'Quit'" part of
set_name is never going to be called.

Otherwise you are doing well.

Hi Nathan,

The executable should be under a bin or exe folder. Bundled documentation
explains that in great detail.
Also you should convert that code into a gem.
See rubygems guides for documentation.

···

On Tue, 13 Dec 2016 at 10:29, Nathan Guilty <ruby@e-solutions.re> wrote:

Hi,

I'm learning Ruby, i just done a small RubyGame to apply what i learned.

Can you review the project ? Im looking for best-practice, refactoring

keeping the 3 classes usage.

The project is here : GitHub - wesley974/rubygame: A game to learn Ruby

Thank you very much.

/Nathan

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Thank you very much for your reply.

The scoreboard works, you need to beat the best time not "tries number" :slight_smile:

/Nathan

···

Le 2016-12-14 02:12, Micky Scandal a écrit :

very nice! as mentioned before it seems like this could be made with a
lot less code (although I understand this is a learning excersize),
also does the scoreboard work right? I'm pretty sure i beat the 3rd
highest score and my name didn't end up in the scoreboard. otherwise,
very nice work!