本文介绍了`%i` 符号的起源是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 经典地支持以下文字:
Ruby has classically supported the following literals:
%q[quack quack] #=> "quack quack"
%r[quack quack] #=> /quack quack/
%w[quack quack] #=> ["quack", "quack"]
%x[echo quack quack] #=> "quack quack\n"
我对这些来源的理解如下:
My understanding of the origin of those are as follows:
%q[]
用于 quotes%r[]
用于 regex%w[]
用于w命令%x[]
用于 execute
%q[]
is for quotes%r[]
is for regex%w[]
is for words%x[]
is for execute
Ruby 2.0 引入了 %i
表示法:
Ruby 2.0 introduced the %i
notation:
%i[quack quack] #=> [:quack, :quack]
为什么是 i
?
推荐答案
它可能参考了 String#intern
方法用于从字符串中获取符号.
It's probably a reference to the String#intern
method used to get a symbol from a string.
"foo".intern #=> :foo
这篇关于`%i` 符号的起源是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!