On Nov 6, 8:22 pm, Todd Benson <caduce... / gmail.com> wrote:
> On 11/6/07, Raymond O'Connor <nappin... / 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.

Exactly.

This line:
p foo { ... }
is interpreted as
p( foo{ ... } )

While this line:
p foo do ... end
is interpreted as
p(foo) do ... end

The lower precedence of do/end is causing it to be bound to the result
of p( foo ), or in your case p( array.sort )