Louis J Scoras
3/1/2007 1:02:00 PM
On 2/28/07, Samantha <rubygeekgirl@gmail.com> wrote:
> After taking several suggestions, I've come up with 91 lines of code
> (including blank lines because I like organizing things).
> I'll post all 91 lines (including lines intentionally left blank), and
> explain what I'm having go wrong... I'm just not getting it, but maybe I
> don't quite understand certain things... (probably, not maybe ;) (And
> please excuse the rude prompts - I'm not really this rude, nor would I write
> such a rude program for deployment into the world.)
Samantha;
Cool script. I like the prompts ;)
One cool thing about ruby is that if you put key/value pairs at the
end of a method call they all get mashed together into a hash. You
can use that to help with readability. For example, many times in the
code you check a boolean condition and then write out a message. You
could try something like this:
def verify_info(ok, hash)
if ok
puts hash[:next]
else
puts hash[:fail]
exit 1
end
end
Now the messages can be passed in like so:
verify_info correct,
:next => "Good, now moving on, let's get a little information
about your skills.",
:fail => "Please come back when you have some goals."
Or even get rid of the "correct" variable:
verify_info boolean_prompt("Is this correct?"),
:next => "Great, let's move onto your experience.",
:fail => "Please come back when you know what you can do with
yourself. :)"
In this case it doesn't afford you too much, but it does get rid of
the repeated pattern. Say you wanted to change the exit code. Now
you'd only need to edit it in one place.
--
Lou.