Forum: Ruby Re: nuby: %w to understand quotes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2006-04-24 02:32
(Received via mailing list)
Justin Collins [mailto:collinsj@seattleu.edu] :

# In that case, wouldn't it be easier to just do
#
# ["sample", "short sample", "there is quite a number of strings longer
# than this"]

that's what i'm doing now (instead of escaping). But as much as
possible, I would like to quote only when needed.

Right now,

irb(main):004:0* %w{test this is a test}
=> ["test", "this", "is", "a", "test"]
irb(main):005:0> %w{test "this is" "a test"}
=> ["test", "\"this", "is\"", "\"a", "test\""]
irb(main):006:0>

The quotes have no use. Maybe ruby 1.9 can make use of them.

kind regards -botp
37c332966b49eeb1d54eeefd3bc5ce97?d=identicon&s=25 David Corbin (Guest)
on 2006-04-24 02:53
(Received via mailing list)
On Sunday 23 April 2006 08:30 pm, Botp wrote:
> Justin Collins [mailto:collinsj@seattleu.edu] :
>
> # In that case, wouldn't it be easier to just do
> #
> # ["sample", "short sample", "there is quite a number of strings longer
> # than this"]
>
> that's what i'm doing now (instead of escaping). But as much as possible, I
> would like to quote only when needed.
>

But why?  %w is intended as a shortcut when everthing is a single word.
For
anything else, use quotes.
This topic is locked and can not be replied to.