【发布时间】:2013-03-29 21:24:50
【问题描述】:
我正在寻找像 Python 对 Ruby 的 if-in 语句。
基本上,如果 x in an_array 做
这是我正在处理的代码,其中变量“line”是一个数组。
def distance(destination, location, line)
if destination and location in line
puts "You have #{(n.index(destination) - n.index(location)).abs} stops to go"
end
end
【问题讨论】:
-
"destination and location in line",意思是destination和location都必须在line?这也不是你用 python 写的方式。
-
如“
destination和location都在line”或“destination为真,location在line”中? -
因为目标和位置都在一个名为 line 的数组中。
标签: ruby arrays if-statement