From: Michael Campbell Date: 2005-08-05T04:51:06+09:00 Subject: Re: Cascading <=> comparisons "Robert Klemme" writes: > Michael Campbell wrote: > > "Robert Klemme" writes: > > > >> David A. Black wrote: > >>> Hi -- > >>> On Sat, 16 Jul 2005, Robert Klemme wrote: > >>> > >>>> This technique can be applied to sort_by, too: > >>>> > >>>>>> hash.sort_by {|a| a.reverse} > >>>> => [["a", 1], ["d", 1], ["c", 3], ["b", 4]] > >>>> But this shows a strange anomaly - this seems like a bug in 1.8.2. > >>>> > >>>>>> hash.sort_by {|a| a.reverse!} > >>>> => [[1, "a"], [1, "d"], [3, "c"], [4, "b"]] > >>> I'll probably figure this out as soon as I hit 'send'... but what's > >>> the anomaly here? > >> And, did you figure in the meantime? It's the different result - > >> IMHO anything that sort_by does should have no such effect on the > >> result. > > Even if the operation is a "bang" one? > > IMO yes. Wow. How do you tell ruby to not do what it normally would? How do reconcile that sort_by {|a| } is different than sort_by {|a| } for any given ? What about OTHER side effects of (like, a database call or something)? -- I tend to view "truly flexible" by another term: "Make everything equally hard". -- DHH