Main.rb
#= Guess numbers#这是一个简单的猜数字游戏#== Gameplay#随机生成一个 The natural number of "1,100", it will prompt the sizeClass Guessnum def playGame wrongint =truec =0 Num= Rand - whileWrongint c+=1Puts"Please enter the number you guessed" 0~100 ""Getnum = getsifGetnum.to_i <NumPuts"small guess."elsif getnum.to_i >NumPuts"big guess." ElsePuts"U Got it! #{c} times are common. "Wrongint =false End End EndEndNewgame = Guessnum.NewNewgame.playgame
Run
Ruby Main.rb
/users/baodong/.rvm/rubies/ruby-2.2.0/bin/ruby- e $stdout. sync=true;$stderr. sync=true; Load ( $=argv.shift)/USERS/BAODONG/RUBYMINEPROJECTS/GUESSNUMBER/MAIN.RB Please enter the number you guessed "0~ -』 -Please enter your guess number "0~ -』 -Guess small Please enter the number you guessed "0~ -』 +Guess small Please enter the number you guessed "0~ -』 -Guess small Please enter the number you guessed "0~ -』 $Please enter your guess number "0~ -』 -Guess small Please enter the number you guessed "0~ -』 -Please enter your guess number "0~ -』 WuU Got it! public.8Times. Process finished withExitCode0
Generate doc
RDoc main.rb
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Ruby first line of code