2013-03-06 80 views

回答

1

否標準中沒有這樣的方法。實現它你自己:在上面的代碼

class Object 
    def is_in? a 
    return a.include?(self) 
    end 
end 

注意我從來不檢查的類型,所以如果include?沒有一個定義,你會得到一個錯誤。

0

以同樣的方式不正是你想要的,但是你可以重寫這個

if [1, 2, 3].include? foo 
    do_this 
else 
    do_that 
end 

這樣:

case foo; when 1, 2, 3 
    do_this 
else 
    do_that 
end