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-22 08:19
(Received via mailing list)
Jake and Matz wrote:

# %w{this\ is a\ test}

cool. escaping the space.

many thanks, jake/matz.

otoh, i am also ending up w lots of escapes like for longer strings

%w{ sample
    short\ sample
    there\ is\ quite\ a\ number\ of\ strings\ longer\ than\ this
  }

if %w will optionally respect quotes, then it may simplify

kind regards -botp
F3b7109c91841c7106784d229418f5dd?d=identicon&s=25 Justin Collins (Guest)
on 2006-04-22 11:08
(Received via mailing list)
Peña wrote:
> %w{ sample
>     short\ sample
>     there\ is\ quite\ a\ number\ of\ strings\ longer\ than\ this
>   }
>
> if %w will optionally respect quotes, then it may simplify
>
> kind regards -botp
>
>
In that case, wouldn't it be easier to just do

["sample", "short sample", "there is quite a number of strings longer
than this"]

etc?

-Justin
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-22 16:14
(Received via mailing list)
On Sat, 22 Apr 2006, [iso-8859-1] Peña, Botp wrote:

> %w{ sample
>    short\ sample
>    there\ is\ quite\ a\ number\ of\ strings\ longer\ than\ this
>  }
>
> if %w will optionally respect quotes, then it may simplify

i use this idiom:


     harp:~ > cat a.rb
     list = %Q[

        sample

        short sample

        there is quite a number of strings longer than this

        it's '#{ Time.now }' now

     ].scan %r/[^\s].*[^\s]/

     require 'yaml'
     y list


     harp:~ > ruby a.rb
     ---
     - sample
     - short sample
     - there is quite a number of strings longer than this
     - it's 'Sat Apr 22 08:11:37 MDT 2006' now


cheers.

-a
This topic is locked and can not be replied to.