使用%i和%I符号数组文字

时间:2016-10-01 05:20:51

标签: ruby-on-rails ruby

通过阅读Rails问题列表,我无法找到%i对符号数组的影响。这对任何人都意味着什么吗?

2 个答案:

答案 0 :(得分:15)

小写%i代表

  

非插值符号数组,由空格分隔(在Ruby 2.0之后)

此外,大写%I表示

  

插值符号数组,由空格分隔(在Ruby 2.0之后)

有关插值的差异示例:

2.4.2 :001 > a = 1
2.4.2 :002 > %i{one two #{a}+three} # Interpolation is ignored
 => [:one, :two, :"\#{a}+three"]
2.4.2 :003 > %I{one two #{a}+three} # Interpolation works
 => [:one, :two, :"1+three"]

请查看here以获取更多信息。

答案 1 :(得分:5)

  

我无法找到class A { @Override public int hashCode() { return 1; } } class B { @Override public int hashCode() { return 1; } } // in some method HashMap<A, Object> map = new HashMap<>(); map.put(new A(), "some stuff"); map.get(new B()); // returns "someStuff"! makes no sense, right? 与符号数组相关的内容。

它是符号数组的数组文字。对于符号数组,它与%i对字符串的作用相同。

相关问题