[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Can anyone try to solve this problems?

Peña, Botp

1/16/2007 4:08:00 AM

From: nobu.nakada@gmail.com [mailto:nobu.nakada@gmail.com]:
# Gregory Brown wrote in [ruby-talk:234222]:
# > ['fodfsafdfsdfso','bar','bazzzzzz'].sort_by { |s| s.length }.pop
#
# max_by(&:length)

Hi Nobu, will the &: notation/feature be incorporated in 1.8.x series?
btw, i'd prefer max(&:length) over max_by..

kind regards -botp

2 Answers

Kalman Noel

1/16/2007 12:18:00 PM

0

Peña, Botp:
> btw, i'd prefer max(&:length) over max_by..

Note the difference in using sort and sort_by, or max and max_by:

enum.max { |x,y| x.length <=> y.length }
enum.max_by { |x| x.length } # 1.9

Kalman

Nobuyoshi Nakada

1/16/2007 5:07:00 PM

0

Hi,

At Tue, 16 Jan 2007 13:07:47 +0900,
Peña, Botp <botp@delmonte-phil.com> wrote in [ruby-talk:234253]:
> Hi Nobu, will the &: notation/feature be incorporated in 1.8.x series?

I don't think so, but Symbol#to_proc was incorporated from
ActiveSupport.

--
Nobu Nakada