2012-10-20 31 views
1

我的Ruby文檔跨越一個例子來了,感到困惑的是確切的含義。我指的是=~。下面的示例使用它,但我不知道那是什麼目的了說==是。意義在Ruby中

a = %w{ a b c d e f } 
a.select {|v| v =~ /[aeiou]/} #=> ["a", "e"] 
+5

你可能想書籤一些文檔:http://ruby-doc.org/core-1.9.3/String.html#method-i-3D-7E –

+0

@muistooshort謝謝。這裏是Ruby 2.1.0文檔。我在Google上找了20分鐘才找到這個,沒有任何運氣。 – Mohamad

+1

@Mohamad:symbolhound.com是你的朋友:http://symbolhound.com/?q=ruby+%3D%7E –

回答

5
if v =~ /[aeiou]/ # if this value matches this regex 
if v == /[aeiou]/ # if this value IS this regex 

看到區別?

+0

感謝。我有一個預感,它可能是因爲正則表達式。 – jason328

2

它匹配正則表達式。