Câu hỏi phỏng vấn Ruby
Câu hỏi

What is the difference between == and === ?

Câu trả lời

In Ruby, the difference between == and === operators is significant and pertains to how they evaluate equality.

The == operator is used to check for equality between two objects. It returns true if the objects are considered equivalent, though what constitutes equivalence can vary depending on the type of the objects and how the == method is implemented in their respective classes. For example, for numeric values, 1 == 1.0 returns true because the numeric value is the same, even though the types (integer and float) are different[1][2].

On the other hand, the === operator, often called the case equality, triple equals, or the "case subsumption" operator, has a broader use. While it can function similarly to == in many cases, it is specifically designed for use in case statements to support more complex comparison logic. In Ruby, === is used to determine if a value falls within a "case" in a case expression. For example, it can check if an object is an instance of a class (String === "str" returns true), if an object falls within a ...

junior

junior

Gợi ý câu hỏi phỏng vấn

middle

Can you tell me the three levels of method access control for classes and modules? What do they imply
about the method?

senior

What will be the result of each of the following lines of code

senior

What happens to a constant which is not assigned?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào