一组冻结字符串的简写

时间:2014-09-04 08:04:54

标签: ruby arrays string

对于单个字符串,适用freeze的解析器优化。

"foo" # => generated every time it is called
"foo".freeze # => generated only once

有没有办法按照使用%w文字的方式创建一个解析器优化的冻结字符串数组?

%w[foo bar baz] # => each string is generated every time it is called
... # => an array of strings generated only once

0 个答案:

没有答案