equality == is based on index only #2

Closed
atomgas opened this Issue Feb 15, 2013 · 3 comments

Projects

None yet

2 participants

@atomgas
atomgas commented Feb 15, 2013

I think something like this is missing

module Renum
  class EnumeratedValue
    def ==(other)
      self.class == other.class && self.<=>(other).zero?
    end
  end
end
@duelinmarkers
Owner

If I'm not mistaken, equality is falling back to identity. If you don't
think that's true, can you provide a failing test case?
On Feb 15, 2013 12:16 PM, "Luzifer Altenberg" notifications@github.com
wrote:

I think something like this is missing

module Renum
class EnumeratedValue
def ==(other)
self.class == other.class && self.<=>(other).zero?
end
endend


Reply to this email directly or view it on GitHubhttps://github.com/duelinmarkers/renum/issues/2.

@atomgas
atomgas commented Feb 21, 2013
irb(main):002:0> enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]
=> [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]
irb(main):003:0> enum :Color, [ :RED, :GREEN, :BLUE ]
=> [Color::RED, Color::GREEN, Color::BLUE]
irb(main):004:0> Status::NOT_STARTED == Color::RED
=> true
irb(main):005:0>
@duelinmarkers
Owner

I'd forgotten Comparable defines ==. Shame. Will fix. Thanks.

On Thu, Feb 21, 2013 at 11:55 AM, Luzifer Altenberg <
notifications@github.com> wrote:

irb(main):002:0> enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]=> [Status::NOT_STARTED, Status::IN_PROGRESS, Status::COMPLETE]irb(main):003:0> enum :Color, [ :RED, :GREEN, :BLUE ]=> [Color::RED, Color::GREEN, Color::BLUE]irb(main):004:0> Status::NOT_STARTED == Color::RED=> trueirb(main):005:0>


Reply to this email directly or view it on GitHubhttps://github.com/duelinmarkers/renum/issues/2#issuecomment-13902964.

http://elhumidor.blogspot.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment