⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00 - introduction

📁 O Reilly Ruby Cookbook source code
💻
字号:
def confirmation_hearings  questions = [['What is your name?', :name],               ['How old are you?', :age],               ['Why would you like to be Secretary of the Treasury?', :why]]  answers = questions.inject({}) do |answers, qv|    question, value = qv    print question + ' '    answers[value] = gets.chomp    answers  end  puts "Okay, you're confirmed!"  return answersendconfirmation_hearings# What is your name?                                  # <= Leonard Richardson# How old are you?                                    # <= 27# Why would you like to be Secretary of the Treasury? # <= Mainly for the money# Okay, you're confirmed!# => {:age=>"26", :why=>"Mainly for the money", :name=>"Leonard Richardson"}#---$ ./confirmation_hearings.rb < answers# => What is your name? How old are you? Why would you like to be #    Secretary of the Treasury? Okay, you're confirmed!#---require 'rubygems'require 'highline/import'def confirmation_hearings  answers = {}  answers[:name] = ask('What is your name? ')  answers[:age] = ask('How old are you? ', Integer) { |q| q.in = 0..120 }  answers[:why] = ask('Why would you like to be Secretary of the Treasury? ')  puts "Okay, you're confirmed!"  return answersendconfirmation_hearings# What is your name?                                  # <= Leonard Richardson# How old are you?                                    # <= twenty-seven# You must enter a valid Integer.# ?                                                   # <= 200# Your answer isn't within the expected range (included in 0..120)# ?                                                   # <= 27# ...#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -