How does Integer === 3 work?

前端 未结 3 964
暗喜
暗喜 2021-01-19 23:53

So as I understand it, the === operator tests to see if the RHS object is a member of the LHS object. That makes sense. But how does this work in Ruby? I\'m loo

3条回答
  •  一整个雨季
    2021-01-20 00:24

    It's defined on Module, which Class is a subclass of, which Integer is an instance of.

    In other words, when you run Integer === 3, you're calling '===' (with the parameter 3) on the object referred to to by the constant Integer, which is an instance of the class named Class. Since Class is a subclass of Module and doesn't define its own ===, you get the implementation of === defined on Module.

    See the API docs for Module for more information.

提交回复
热议问题