Ruby和Rails,什么';ActiveRecord类比较的==和===之间的区别是什么?

Ruby和Rails,什么';ActiveRecord类比较的==和===之间的区别是什么?,ruby,Ruby,我在做一些案例。。当..时,我发现了这种行为 case vehicle.class when Bike puts "This is a Bike" when Car puts "This is a car" else puts "May be it's an UFO." raise "ALIENS" end 我发现,尽管变量vehicle是Bike的一个实例,但它并没有生成输出“This is a Bike”。相反,它引发了一个例外 我觉得这很奇怪,因为下面的代码输出的是一个字

我在做一些
案例。。当..
时,我发现了这种行为

case vehicle.class
when Bike
  puts "This is a Bike"
when Car
  puts "This is a car"
else
  puts "May be it's an UFO."
  raise "ALIENS"
end
我发现,尽管变量
vehicle
Bike
的一个实例,但它并没有生成输出“This is a Bike”。相反,它引发了一个例外

我觉得这很奇怪,因为下面的代码输出的是一个字符串

case "FooBar"
when String
  puts "It's a string"
else
  puts "It's not a string"
end
我在
better\u errors
的活动shell中进行了尝试,发现了以下内容

>> vehicle.class
=> Vehicle(id:integer, name: string, … , updated_at: datetime)
>> Vehicle
=> Vehicle(id:integer, name: string, … , updated_at: date time)

>> vehicle.class == Vehicle
=> true
>> vehicle.class === Vehicle
=> false

或者这与
机架环境有关吗?

如果
车辆
自行车
的实例,则
自行车===车辆
。另一方面,
vehicle.class
Bike
,因此
Bike==vehicle.class
Bike==Bike
相同,这是
false
,因为
Bike
的类别是
class
,而不是
Bike

起飞
class

case vehicle
when Bike
  puts "This is a Bike"
when Car
  puts "This is a car"
else
  puts "May be it's an UFO."
  raise "ALIENS"
end

=
在后台的
case
语句中使用,并测试右侧是否是左侧类的成员。(请注意,其结果是不可交换的。)

>Fixnum==2
=>正确
>>二类车辆;终止
=>零
>>货车类<汽车类;终止
=>零
>>卡车===卡车。新
=>正确
>>车辆===卡车。新
=>正确
>>卡车。新===卡车
=>错误
>> Fixnum === 2
=> true
>> class Vehicle; end
=> nil
>> class Truck < Vehicle; end
=> nil
>> Truck === Truck.new
=> true
>> Vehicle === Truck.new
=> true
>> Truck.new === Truck
=> false