Ruby中=〜的含义
我在Ruby文档中遇到了一个例子,我对它的确切含义感到困惑。 我指的是=~
。 下面的示例使用它,但我不确定它的目的是什么==
。
a = %w{ abcdef } a.select {|v| v =~ /[aeiou]/} #=> ["a", "e"]
if v =~ /[aeiou]/ # if this value matches this regex if v == /[aeiou]/ # if this value IS this regex
看到不同?
它匹配正则表达式。