开发者

Ruby - Help with array literals

开发者 https://www.devze.com 2023-02-11 15:05 出处:网络
I know how to do this: %w(doc ppt xls).include?(fileext) I now need something similar but the match terms have spaces in them. I\'ve tried

I know how to do this:

%w(doc ppt xls).include?(fileext)

I now need something similar but the match terms have spaces in them. I've tried

%w("blah blah" "开发者_运维问答yada yada" "wowowow").include?(actiontype)

Goal here is to see if actiontype exists inside one of the quotes or not. Ideas?

Thanks


["blah blah", "yada yada", "wowowow"].include?(actiontype)

Or, you could choose to escape spaces.

%w(blah\ blah yada\ yada wowowow).include?(actiontype)

This second example really only makes sense when you rarely have a space, like:

%w(yellow red blue orange green black dark\ blue purple).include?(color)


["blah blah", "yada yada", "wowowow"].include?(actiontype)


If you're looking for an exact match, just use an array.

["blah blah", "yada yada", "wowowow"].include?(actiontype)

If it's something else that you're looking for, please ask a more specific question and include an example input and desired output.

0

精彩评论

暂无评论...
验证码 换一张
取 消