检查项目是否包含在数组或散列中

and*_*aer -6 ruby

在Ruby中是否可以使用这样的东西

if @subscription.state = ['trail', 'active']
   #Do something 
end
Run Code Online (Sandbox Code Playgroud)

应该是自我解释的.

pab*_*rti 7

也许:

['trail', 'active'].include?(@subscription.state)
Run Code Online (Sandbox Code Playgroud)


Hun*_*der 5

你可以使用include?ruby的方法Array

if ['trail', 'active'].include?(@subscription.state)
  #do something
end
Run Code Online (Sandbox Code Playgroud)