-2
wordSort.sort!

=begin
Conditional is performed on the array: if array index is equal to zero or has 
a remainder of zero after being divided by 2 then call upcase method on element.
Else call lowercase method on that index number.
=end

puts ""

puts "Here are the words you entered:"

puts wordSort
4

1 回答 1

1
enum = [:upcase, :downcase].cycle
  #=> #<Enumerator: [:upcase, :downcase]:cycle> 
"Here are the words you entered:".gsub(/\w+/) { |x| x.send enum.next }
  #=> "HERE are THE words YOU entered:"
于 2016-04-02T22:38:43.323 回答