+ 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?

27th Sep 2019, 1:46 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
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
27th Sep 2019, 2:45 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar