I was curious when this did not work, as I expected:
var = "foo" case var.class when String puts "bar" else puts "baz" => "baz"
I understand that the case statement uses ===, but I do not understand what it does ===. Documents say ...
===
Random equality. For the Object class, it is in fact the same as calling # ==, but it is usually overridden by descendants to provide meaningful semantics in case statements.
http://ruby-doc.org/core-2.2.3/Object.html#method-i-3D-3D-3D
Does this mean that ===in a class (or one of its modules) it overrides ===to Object? I'm confused.
=== Class (, , Module ), " ".
Class
Module
:
>> String === "" => true >> Class === String => true
, . , :
var = "foo" case var when String puts "bar" else puts "baz" end # outputs "bar", since String === "foo"
: Ruby String === String, , String .
String === String
String
case equality. . Module .
case equality
Case Equality - true, . , case .
=== Ruby is_a?.
is_a?
false, "Foo".class string.
"Foo".class
"Foo".class.is_a?(String) => false
This is due to the way the case equivalence operator is used for classes ===. Use an object, not object.class
var = "foo" case var when String puts "bar" else puts "baz" => "bar"
Source: https://habr.com/ru/post/1618039/More articles:get List.size () value on JSP page? - javaSend an email using javax.mail using your existing InputStream as attachment content - javaкаковы опасности использования Mutable thisarg или контекста с помощью javascript - javascriptCMD Echo Command сохраняет только последнюю строку текста - windowsAVPlayerItemStatus Error when too many instances of AVPlayer occur - iosHow to disconnect AVPlayer from AVPlayerItem? - iosSimplification-Java (by hgoebl) Problem with a list of abbreviated points Always size 2 - javaInfluxDB Betting - Time-seriesClear screen in watch command - linuxlimitations of button buttons in yii2 - phpAll Articles