Rails - Using %W

后端 未结 4 796
借酒劲吻你
借酒劲吻你 2021-02-06 21:43

I have the following which works well:

def steps
    %w[hello billing confirmation]
end

steps.first

But I want to do this:

  d         


        
4条回答
  •  旧巷少年郎
    2021-02-06 22:16

    %w[hello billing confirmation] is syntax sugar for ["hello", "billing", "confirmation"]. It tells Ruby to break up the input string into words, based on the whitespace, and to return an array of the words.

    If your specific use case means the values in the array are permitted to have spaces, you cannot use %w.

    In your case, ['Upload a photo', 'Billing Info', 'Confirmation Screen'] suffices.

提交回复
热议问题