DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fancy Little Ruby Input Prompter

01.19.2008
| 3119 views |
  • submit to reddit
        
for i in 1..100
  print "Now at #{i}. Restart? "
  retry if gets =~ /^y/i
end
    

Comments

Snippets Manager replied on Tue, 2007/04/10 - 11:52pm

Might have been more Rubyish if it had been: 1.upto(100) do |num| print("\nNow at #{num}. Restart? ") retry if gets =~ /^y/ end The 'i' and for/loop were unnecessary if you use blocks. :-) Might be more optimizations, but that one sort of leaped out at me.