Hi there, I was looking around for some beginners forum for ruby to
share little portions of code and help each other with some mistakes on
them, or trying to improve it.
I've been playing around with ruby for the last 2 weeks and I've
followed lots of guides and video tutorial, but when I tried to port
some C++ codes to ruby just to practise a bit I found lots of problems
with simple things as getting input data from the keyb. Finally I did:
print "Type the first number: "
a = gets.to_i
print "Type the second number: "
b = gets.to_i
But it doesn't look too good to me, is there any more elegant way to get
Anyway... I'm not sure if this is the right place for asking such
things, so that's why I was asking for another specific beginners forum.
As there is no beginners forum, this is indeed the right place to ask,
I also daresay that you will be well taken care of
Now concerning your code above, it is a reasonable approach, maybe you
could do some things a little bit differently
print "Type the fourtysecond number:"
$stdout.flush # if necessary and some of us prefer the global variable
to the constant, but I forgot why, LOL
b = Integer gets.strip # This variation to using String#to_i might
be interesting, I show you in irb why
irb(main):003:0> Integer "42"
irb(main):005:0> puts "So far so good, but ;)"
So far so good, but
irb(main):007:0> Integer "ade"
ArgumentError: invalid value for Integer: "ade"
from (irb):7:in `Integer'
irb(main):008:0> puts "Is maybe a better behaviour, is it not?"
Is maybe a better behaviour, is it not?
On Thu, Jun 12, 2008 at 11:57 AM, Simon Blanco <firstname.lastname@example.org> wrote:
As simple as possible, but not simpler.