我在和“有吗?”方法在块中。片段正在寻找字符串(拆分) check中的字符串"CA“
region="CA"
check="AU,US,UK,CA,ZA"
if check.split(',').any? { |r| region[r] }
puts "This is true!"
end我知道“有吗?”命令起不到的作用是,当r值为"CA“时,为什么解析为true --因此我们有区域”CA“给我们trueE 212!
我可以看到"CA""CA“是真的,但为什么呢?我在这里少了一点知识。
发布于 2011-11-04 05:35:54
从String方法[]和片,http://www.ruby-doc.org/core-1.9.2/String.html#method-i-5B-5D
str[other\_str] → new\_str or nil str.slice(other\_str) → new\_str or nil If a String is given, that string is returned if it occurs in str.
https://stackoverflow.com/questions/8005242
复制相似问题