[LRUG] ShRUG Golf update

Hakan Şenol Ensari hakan.ensari at papercavalier.com
Thu May 12 05:04:38 PDT 2011


This fixes the infamous one-letter-word-does-not-have-a-second-letter bug.

sentence.split.sort_by{ |a| a[1] || 'z' } * ' '

Hakan

http://hakanensari.com




On Thu, May 12, 2011 at 11:34 AM, Paul Battley <pbattley at gmail.com> wrote:

> On 12 May 2011 10:54, Jordi Noguera Leon <jordinoguera83 at gmail.com> wrote:
> > It could be shortened into:
> > sentence.split(' ').sort_by{ |a| a[1] }.join ' '
>
> * If the parameter is unspecified, the default behaviour for split is
> to split on " ".[1]
>
> * String#join is aliased to String#*
>
> Thus, we can write it even shorter as:
>
> sentence.split.sort_by{ |a| a[1] } * " "
>
> 1. This is due to the fact that the default is $;, which defaults to
> nil, which means that you can use $; instead of nil to save a byte if
> you need nil anywhere.
>
> Paul.
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110512/6aa61133/attachment.html>


More information about the Chat mailing list