F. Senault
7/19/2007 12:55:00 PM
Le 19 juillet à 14:32, Robert Klemme a écrit :
> This does not work.
>
> irb(main):003:0> [nil].sort_by {|it| it.send(:length) || 0}
>> [nil, "aaaaaaa", "aaa", "a" ].sort_by {|it| (it && it.send(:length)) || 0}
=> [nil, "a", "aaa", "aaaaaaa"]
(Or even without the parenthesis.)
Fred
--
An ASCII character walks into a bar and orders a double. 'Having a bad
day?' asks the barman. 'Yeah, I have a parity error,' replies the ASCII
character. The barman says, 'Yeah, I thought you looked a bit off.'
(Kirrily 'Skud' Robert)