Custom usage of %w in Ruby

来源:互联网 发布:手机淘宝店铺怎么描述 编辑:程序博客网 时间:2024/05/14 21:47

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.


0 0
原创粉丝点击