+ 2
Ruby - Is equal? more restrictive than eql?
Consider the following code (output: True, False): s1,s2 = "a","a" puts s1.eql?(s2) if s1.eql?(s2) puts s1.equal?(s2) end Does this mean equal? is more restrictive in checking than eql? What's the difference?
1 Réponse
+ 3
The equal? method checks if the two variables refer to the same object. Eql? method checks if the two variables refer to the same hash keys. In some cases it could be replaced by "==" check, but there are some exceptions. You can find more info here: https://medium.com/@khalidh64/difference-between-eql-equal-in-ruby-2ffa7f073532