Skip to content

Comparison is not commutative #20

@vmeyet

Description

@vmeyet

see the following:

Semantic::Version.new('1.0.0') == '1.0.0'
# true
'1.0.0' == Semantic::Version.new('1.0.0')
# false

IMO this should returns the same value. Surprising behaviors should be avoided at all cost (https://en.wikipedia.org/wiki/Principle_of_least_astonishment).

I know that on Numeric classes there is a special method called coerce that allow to change the comparison object without changing the base class (class of the instance on the left of the operator).

But coerce doesn't seem to exist on String.

So I'm not sure what could be the right approach here.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions