首页 > 代码库 > Ruby_day[1]控制流2

Ruby_day[1]控制流2

summary:

  1: puts "s in #{user_input}" 和puts ‘s in #{user_input}‘不同,前者#{user_input}会输出user_input的值,后者只是输出鸳原样,s in #{user_input}

  

 1 print "Thtring, pleathe!: " 2 user_input = gets.chomp 3 user_input.downcase! 4  5 if user_input.include? "s" 6   user_input.gsub!(/s/, "th") 7 else 8   puts "Nothing to do here!" 9 end10   11 puts "Your string is: #{user_input}"

 

(As a general rule, Ruby methods that end with ? evaluate to the boolean values true or false.

Ruby_day[1]控制流2