From: John Kaurin Date: 2001-05-03T12:10:03+09:00 Subject: [ruby-talk:14572] Re: why doesn't do/end work for sort block? "David Alan Black" wrote in message news:Pine.LNX.4.30.0105022209570.16494-100000@candle.superlink.net... > Hello -- > > Just wondering why: > > ary = [1,2,3,4,5] > > p ary.sort {|a,b| b <=> a} > # => [5, 4, 3, 2, 1] > > # but > > p ary.sort do |a,b| b <=> a end > # => [1, 2, 3, 4, 5] > > # and even > p ary.sort do |a,b| puts "Hi!" ; b <=> a end > # => [1, 2, 3, 4, 5] > > > The do/end blocks seem to be discarded. Same for Enumerable#max and > #min. > > > David > > -- > David Alan Black > home: dblack@candle.superlink.net > work: blackdav@shu.edu > Web: http://pirate.shu.edu/~blackdav > Somewhere in the pickaxe book (I cannot find it now) it stated that do ... end on a single line was illegal, unsupported, or some such thing. Maybe the block is just ignored due to this? However, when I run your code, as is, on my Windows box I get: [5, 4, 3, 2, 1] [5, 4, 3, 2, 1] Hi! Hi! Hi! Hi! Hi! Hi! [5, 4, 3, 2, 1]