From: Robert Klemme on
2010/3/25 Brandon Jones <brandon.g.jones(a)gmail.com>:
> Robert Klemme wrote:
>> Even shorter (6 chars if I'm not mistaken):
>>
>> a = %w{123 456 raju}
>> a.map!{|x|"91#{x}"}
>>
>> ;-)
>>
>> Kind regards
>>
>> robert
>
> oh yeah?!? well take this
>
> %w(123 456 raju).map{|x|"91#{x}"}
>
> not exactly the same, as there is no persistent variable, but it is a
> bit shorter

You're absolutely right. My main point - which I failed to mention -
was, that arrays of strings can be easier represented with the %w
notation. This works of course only if strings need not contain white
space.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

From: jbw on
[Note: parts of this message were removed to make it a legal post.]

On Thu, Mar 25, 2010 at 11:17 PM, Robert Klemme
<shortcutter(a)googlemail.com>wrote:

> 2010/3/25 Brandon Jones <brandon.g.jones(a)gmail.com>:
> > Robert Klemme wrote:
> >> Even shorter (6 chars if I'm not mistaken):
> >>
> >> a = %w{123 456 raju}
> >> a.map!{|x|"91#{x}"}
> >>
> >> ;-)
> >>
> >> Kind regards
> >>
> >> robert
> >
> > oh yeah?!? well take this
> >
> > %w(123 456 raju).map{|x|"91#{x}"}
> >
> > not exactly the same, as there is no persistent variable, but it is a
> > bit shorter
>
> You're absolutely right. My main point - which I failed to mention -
> was, that arrays of strings can be easier represented with the %w
> notation. This works of course only if strings need not contain white
> space.
>
> Kind regards
>
> robert
>
>
> --
> remember.guy do |as, often| as.you_can - without end
> http://blog.rubybestpractices.com/
>
>

I think %w[] would be more syntactically meaningful than curly
braces, square brackets remind us of
arrays. I think it is especially important when using shortcuts, which can
be obscure, to be as clear as possible.
--
jbw