我定義一個只有一個參數的方法:有沒有辦法將輸入參數設置爲一系列值?
def numbers(int)
end
我想這對評估值範圍的參數條件語句:
def numbers(int)
if # int != (1,2,3,4,5,6,7,8,9,10) (not legal Ruby)
puts "Cats"
end
end
在這種情況下,如果int
是不等於1
,2
,3
,4
,5
,6
,7
,8
,9
,或10
,puts "Cats"
。
例子:
def numbers(11) => "Cats"
我怎樣才能建立一個範圍內也是這樣嗎?我試過!= (1..10)
,但那不起作用。
而Rails中,你也可以這樣寫:'INT .in?(1..10)' – spickermann 2014-10-17 02:12:21
無聊,但要做到這一點。 – 2014-10-17 02:56:32