Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree::Money should be comparable #1650

Closed
eoinkelly opened this issue Dec 14, 2016 · 4 comments
Closed

Spree::Money should be comparable #1650

eoinkelly opened this issue Dec 14, 2016 · 4 comments

Comments

@eoinkelly
Copy link

Is there a reason why Spree::Money does not implement <=> and include Comparable? The current implementation manually implements #== but not <=>. I think it would be convenient to be able to sort Spree::Money instances directly rather than having to reach into their wrapped Money instances.

I'm happy to have a go at a PR for this. Is there any constraint/reason I'm not seeing that would make it a bad idea?

@mamhoff
Copy link
Contributor

mamhoff commented Dec 15, 2016

We'd like Spree::Money to implement all the things that the base Money object supports, one by one. If this particular itches you, by all means submit a PR!

@kennyadsl
Copy link
Member

kennyadsl commented Dec 15, 2016

@eoinkelly How do you want to implement this? I think we only should allow comparing Money objects that have the same currency with <=>.

@jhawthorn
Copy link
Contributor

@kennyadsl I agree. That seems to be how ::Money works already, so delegating to that will have the desired behaviour.

> ::Money.new(10) < ::Money.new(20)
=> true
> ::Money.new(10) > ::Money.new(20)
=> false
> ::Money.new(10, "USD") < ::Money.new(20, "CAD")
ArgumentError: comparison of Money with Money failed

@eoinkelly A PR would be most welcome

@eoinkelly
Copy link
Author

Not comparing across currencies seems sensible. I'll have a go at a PR and then we'll have something concrete to discuss.

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

No branches or pull requests

4 participants