I was feeling a bit bored so I decided to take a look at Ruby on Rails. I have only been working with it’s code for a day. So far this is the best thing I have come up with:

#!/usr/local/bin/ruby

value_is_not = "q"

while ($_ != value_is_not)
        print "Enter value or q to quit: "
        gets
        chomp

        unless $_ == value_is_not
                puts $_ + " accepted."
        else
                puts "Quit"
        end
end

This will produce something to the effect of:

rails@rails.zepr.net [~/www/dev]# ./while2
Enter value or q to quit: FUN
FUN accepted.
Enter value or q to quit: fun
fun accepted.
Enter value or q to quit: q
Quit
rails@rails.zepr.net [~/www/dev]#

Its nothing special by any means however, it took me awhile to realize that $_ is the only variable that the method chomp likes (I think.)

Technorati Tags:

Post a Comment

*
*