Rails - 使用 %W [英] Rails - Using %W

查看:43
本文介绍了Rails - 使用 %W的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下效果很好:

def steps
    %w[hello billing confirmation]
end

steps.first

但我想这样做:

  def step_title
    %w['Upload a photo' 'Billing Info' 'Confirmation Screen']
  end

steps.first

%w 是如何允许的?我试过谷歌搜索,但谷歌对这些类型的字符很弱.

How does %w allow for that? I tried a google search but google is weak with these types of characters.

谢谢

推荐答案

%w 创建一个单词数组",并使用空格分隔每个值.由于您想分隔另一个值(在这种情况下,引号外的空格),只需使用标准数组:

%w creates an "array of words," and uses whitespace to separate each value. Since you want to separate on another value (in this case, whitespace outside sets of quotation marks), just use a standard array:

['Upload a photo', 'Billing Info', 'Confirmation Screen']

这篇关于Rails - 使用 %W的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆