From: Stefan Lang Date: 2005-10-30T01:32:43+09:00 Subject: Re: "Readability" inflation On Saturday 29 October 2005 18:00, Brian Schr�der wrote: > On 29/10/05, Trans wrote: > > Brian Schr�der wrote: > > > If you are so bold, I have to chime in again to say that > > > > > > ary.sort_by :meth > > > > > > reads a lot better than > > > > > > ary.sort_by.meth > > > > > > because we don't do method chaining here. > > > > > > Sorry, could not resist. ;-) > > > > Ahhhhh... but can you do: > > > > ary.sort_by.meth(foo, bar, wack!) > > > > T. > > And what does that mean and how often do I need it? Perhaps he means something like: % cat sort_by.rb module Enumerable alias _core_sort_by sort_by def sort_by(*args, &block) if args.empty? _core_sort_by(&block) else _core_sort_by { |a| a.__send__(*args, &block) } end end end if $0 == __FILE__ class Factor attr_reader :number def initialize(number) @number = number end def apply_to(other_number) @number * other_number end end list = [Factor.new(-2), Factor.new(3)] p list.sort_by(:number) p list.sort_by(:apply_to, -1) end % ruby sort_by.rb [#, #] [#, #] -- Stefan