当我读野兽的源代码,我发现了很多这样的代码:

<%= 'Password'[:password_title] %>

看起来为[]的方法的调用与符号作为输入参数为字符串我,但我没有找到这种类型的字符串[]红宝石API中方法的参数的。这是什么意思? 由于事先。

有帮助吗?

解决方案

这是由“乱码”增加了一个方法插件野兽用途,国际化。请记住,在Ruby类是开放的,所以你不能总是在这样的情况下的标准API算!

其他提示

在兽源,检查了乱码插件其中String类被修改以接受在括号函数的符号。

本身String类不执行任何操作通过施加str[symbol]方法合理。

str[fixnum] => fixnum or nil
str[fixnum, fixnum] => new_str or nil
str[range] => new_str or nil
str[regexp] => new_str or nil
str[regexp, fixnum] => new_str or nil
str[other_str] => new_str or nil

这是我发现了什么。如果符号这里是等于字符串,我还是不明白的代码的含义。为什么不能简单地用:

<%= 'password' %>

甚至:

password
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top