我定义了一些范围变量
team_numbers = 1..11
defence_numbers = 2..5
center_numbers = 6..8
attack_numbers = 9..11
为什么此代码返回false?
puts (team_numbers === attack_numbers)
team_numbers范围不包括attack_numbers吗?
答案 0 :(得分:1)
rng === obj→true或false
如果obj是范围的元素,则返回true,否则返回false。
这就是为什么会出现以下结果:
(1..4) === 3 # => true
(1..4) === (1..3) # => false
(1..4) === (1..4) # => false
假设您从表达式false
按预期得到puts (team_numbers === attack_numbers)
。