Randy Shipp
2/19/2007 6:41:00 PM
On Apr 1 2006, 8:12 pm, Jan_K <n...@none.com> wrote:
> Solution for the 1st exercise in chapter 8:
>
> (I'm skipping the 2nd exercise - just a bunch of busywork)
>
> -----------------------------------------------------------------------
> input = []
>
> while input.last != ''
> input.push gets.chomp
> end
>
> puts input.sort
> -----------------------------------------------------------------------
----------
To reset slightly, this is an exercise that tells you to accept words
from the user until they just hit Enter, then alphabetize the list.
My problem with the exercise is that the sort method alphabetizes
capital letters before lowercase letters. Therefore, if input ==
[ant, bear, Zebra], the output of
puts input.sort
is
Zebra
ant
bear
....which is clearly not what most users will expect. Short of
changing the line in the program to read
input.push gets.chomp.downcase
(thus altering the entered words in a possibly undesirable way), how
can we get the sort to work the way we might expect? Thanks in
advance.
Randy...