On 11/6/07, Raymond O'Connor <nappin713 / yahoo.com> wrote:
> When I store the result of the sort, everything is fine:
>
> Correct
> result = [2, 4, 3, 7, 1, 8, 9, 8].sort do |a, b|
>   b <=> a
> end
>
> p result #[9, 8, 8, 7, 4, 3, 2, 1]
>
>
>
>
> But when just do a p on the sort, the problem occurs
>
> Incorrect
> p [2, 4, 3, 7, 1, 8, 9, 8].sort do |a, b|
>   b <=> a
> end #[1, 2, 3, 4, 7, 8, 8, 9]

May have something with how the parser sees do/end, (), and {}
precedence.  Interesting.

p [2, 4, 3, 7, 1, 8, 9, 8].sort do |a, b|
  b <=> a
end #[1, 2, 3, 4, 7, 8, 8, 9]

p [2, 4, 3, 7, 1, 8, 9, 8].sort { |a, b|
  b <=> a
} #[9, 8, 8, 7, 4, 3, 2, 1]

p( [2, 4, 3, 7, 1, 8, 9, 8].sort do |a, b|
    b <=> a
  end
) #[9, 8, 8, 7, 4, 3, 2, 1]

You can see the same behavior with...

p [1, 2, 3].map do |i|
  i + 1
end #[1, 2, 3]

p [ 1, 2, 3].map { |i|
  i + 1
} #[2, 3, 4]

Todd