Skip to content

Conversation

@asomers
Copy link
Contributor

@asomers asomers commented Aug 7, 2017

ActiveRecord requires these methods for seriaization. <=> is
insufficient

ActiveRecord requires these methods for seriaization.  <=> is
insufficient
@smortex
Copy link
Contributor

smortex commented Aug 29, 2017

Is there a reason we can't rely on <=> to implement this?

Something like:

def ==(oth)
  (self <=> oth) == 0
end

Also, moving this in a common base class would avoid code duplication 🤔.

@asomers
Copy link
Contributor Author

asomers commented Aug 29, 2017

@smortex that would work in a statically typed language, but not in Ruby. Consider this:

irb(main):002:0> IPAddress.parse("1.2.3.4") == nil
NoMethodError: undefined method `to_u32' for nil:NilClass
        from /usr/local/lib/ruby/gems/2.3/gems/ipaddress-0.8.3/lib/ipaddress/ipv4.rb:512:in `<=>'
        from (irb):2:in `=='
        from (irb):2
        from /usr/local/bin/irb:11:in `<main>'

@smortex
Copy link
Contributor

smortex commented Aug 29, 2017

Hum, this looks like a side effect of the wrong behavior of <=> (see #76).

Reading this old PR, I wonder if it is not just enougth to have the proper <=> which does not produce exception, and == would work as expected (#77 is related).

@asomers
Copy link
Contributor Author

asomers commented Aug 29, 2017

@smortex that looks like it would work.

@smortex
Copy link
Contributor

smortex commented Aug 30, 2017

OK, therefore I close this PR, and the discussion continues in the related PRs.

Thanks!

@smortex smortex closed this Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants