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

Ensure coerce only applies to multiplication #535

Merged
merged 1 commit into from
Sep 29, 2015

Conversation

antstorm
Copy link
Contributor

@antstorm antstorm commented Jul 6, 2015

Resurrected @semmons99's commit from last year, that properly handles coercion for non-Money objects. Raises a TypeError in cases like 0 - Money.new(1), where it otherwise produces a wrong result.

Here's some discussion around this — RubyMoney/money-rails#343

P.S. reopened a PR because of the failing TravisCI build. There's an issue with a "thread safe" test that's failing randomly.

@antstorm
Copy link
Contributor Author

@RubyMoney/money-rails-devs any thoughts on this one?

@ct-clearhaus
Copy link
Contributor

Related to #405?

@antstorm
Copy link
Contributor Author

@ct-clearhaus yeah, didn't notice that. Will read through that PR and see what needs to be changed to merge it.

@paulodiniz
Copy link
Member

👍

@semmons99
Copy link
Member

status?


def +(other) raise TypeError; end
def -(other) raise TypeError; end
def /(other) raise TypeError; end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say division is valid for coercion as you would not divide $10 by $2, but you would divide $10 by 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % modulo operator should also be included with the same treatment as division.

@createdbypete
Copy link
Contributor

I think this is a great improvement and feel Money is right to be strict on the objects it will interact with. 👍 :shipit:

semmons99 added a commit that referenced this pull request Sep 29, 2015
Ensure coerce only applies to multiplication
@semmons99 semmons99 merged commit b651304 into RubyMoney:master Sep 29, 2015
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.

6 participants