Rails - Using %W

后端 未结 4 778
借酒劲吻你
借酒劲吻你 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:10

    You can also use the backslash to escape spaces:

    %w@foo\ bar bang@
    

    is the same as:

    [ 'foo bar', 'bang' ]
    

    In your example I wouldn't use the %w notation, because it's not that clear.

    PS. I do like mixing the delimiter characters, just to annoy team members :) Like this:

    %w?foo bar?
    %w|foo bar|
    %w\foo bar\
    %w{foo bar}
    

提交回复
热议问题