Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Data#eql?
(untyped) -> bool
self.eql?(other) → true or false
struct.c
View on GitHub ↗
#define rb_data_eql rb_struct_eql
Equality check that is used when two items of data are keys of a Hash.
The subtle difference with == is that members are also compared with their eql? method, which might be important in some cases:
Example
Measure = Data.define(:amount, :unit) Measure[1, 'km'] == Measure[1.0, 'km'] #=> true, they are equal as values # ...but... Measure[1, 'km'].eql? Measure[1.0, 'km'] #=> false, they represent different hash keys
See also Object#eql? for further explanations of the method usage.