Ruby百分比 - 宏(la%q,%x,%w)用于整数列表?

Dro*_*ans 1 ruby macros

我找不到使用此列表中的 Ruby宏定义整数列表的方法.

这是我唯一的选择吗?

%w(123 456).map { |i| i.to_i }
Run Code Online (Sandbox Code Playgroud)

我认为%i(123 456)会包括在内,但我想不会.

tad*_*man 7

这样的实用方法可用于处理引用和转义问题,这些问题都不存在于数字列表中.

例如,处理使用两种报价样式的情况:

'Johnny\'s dad\'s friend said, "I really hate backslashes!"'
%Q{Johnny's dad's friend said, "I really hate backslashes!"}
Run Code Online (Sandbox Code Playgroud)

对于字符串列表:

[ 'this', 'that', 'and', 'the', 'other', 'thing' ]
%w[ this that and the other thing ]
Run Code Online (Sandbox Code Playgroud)

对于经常出现斜杠的正则表达式:

/https?:\/\/([\w\-]+).com\//
%r{https?://([\w\-]+).com/}
Run Code Online (Sandbox Code Playgroud)

但是,在定义数字列表时,不需要特定的转义.