1.安裝 Ubuntu 14.04
sudo apt-get install ruby
version 1.9.1
2.命令列執行: irb
3.文擋檢視:man RDoc
4.猜數字 2.2.7程式
guess_number = rand(10) puts "guess the number:" input_number = gets().to_i() success = false while(!success) if(input_number < guess_number) puts "small" else if(input_number > guess_number) puts "large" else success = true break end end input_number = gets().to_i() end puts "You are greate." if success
elsif
guess_number = rand(10) puts "guess the number:" input_number = gets().to_i() success = false while(!success) if(input_number < guess_number) puts "small" elsif(input_number > guess_number) puts "large" else success = true break end input_number = gets().to_i() end puts "You are greate." if success
不需要引入庫,這個比Python還高階
執行:ruby guess_number.rb