在“ Is it possible to sort a list of objects based on if the individual object's response to a method? ”中,我发现飞碟不适用于布尔值。
考虑:
红宝石 1.8.7:
[true, false].sort # => undefined method `<=>' for true:TrueClass (NoMethodError)
true <=> false # => undefined method `<=>' for true:TrueClass (NoMethodError)
红宝石 1.9.3:
[true, false].sort # => comparison of TrueClass with false failed (ArgumentError)
true <=> false # => nil
true <=> true # => 0
false <=> true # => nil
它可能与 true 和 false 没有规范的排序顺序有关,因为哪个先出现?但是,这对我来说听起来很弱。
这是一个错误sort
吗?