[LRUG] ShRUG Golf update

Paul Battley pbattley at gmail.com
Thu May 12 03:34:21 PDT 2011


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.



More information about the Chat mailing list