您的位置:首页 > 编程语言 > Ruby

Custom usage of %w in Ruby

2015-03-03 15:53 211 查看
I know that 
%w
 or 
%W
 is
used for constructing an array of strings. But I have a custom requirement:

Using 
%w
,
I would like to get the following array pattern:
["First Name", "Middle Name", "Last Name", "Email"]


Is it possible?

The space between the strings are making issues.

Thanks for any help offered :)

-----------------------------------------------------------------------------------

You'll have to use character escaping to escape the space, like so:
result = %w(First\ Name Middle\ Name Last\ Name Email)


Though not sure if that reads any clearer than putting them in quotes.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: