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
Asked
Active
Viewed 160 times
-2

vgoff
- 10,980
- 3
- 38
- 56
-
Do you want to return a string or an array? If a string, your description of the problem contains the implicit assumption that it is necessary to convert the string to an array of words, changes cases, then join the elements of the array back into a string. It makes more sense to operate on the string directly. If you wish to return an array, the string can be split into an array or words before or after the changes to case are made. – Cary Swoveland Apr 02 '16 at 22:45
-
1Homework question without any evidence of any attempt. – New Alexandria Apr 02 '16 at 22:46
-
One of Ruby's conventions is to use "snake case" for names of variables and methods. Such names are to begin with a lowercase letter, followed by lowercase letters, digits and underscores. For example, you would write `word_sort` rather than `wordSort`. You don't have to accept the convention, but 99%+ of Rubiests do. – Cary Swoveland Apr 02 '16 at 22:50
-
If you found any of the answers helpful, please consider selecting (i.e, ✅) the one you liked best. (Yes, I realize there is but one answer.) – Cary Swoveland Sep 17 '16 at 00:58
1 Answers
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:"

Cary Swoveland
- 106,649
- 6
- 63
- 100