-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
是否要返回字符串或数组?如果是字符串,那么对问题的描述包含隐含的假设,即需要将字符串转换为字数组,然后将数组元素重新加入字符串中。直接操作字符串更有意义。如果您希望返回一个数组,则可以在对大小写进行更改之前或之后将该字符串拆分为一个或多个数组。 –
没有任何证据的任何企图的家庭作业问题。 –
Ruby的惯例之一是使用“蛇情况”来表示变量和方法的名称。这些名称以小写字母开头,后跟小写字母,数字和下划线。例如,你会写'word_sort'而不是'wordSort'。你不必接受这个约定,但是99%以上的Rubiests都可以。 –