Adding ability to temporarily change the rounding mode#343
Adding ability to temporarily change the rounding mode#343semmons99 merged 6 commits intoRubyMoney:masterfrom
Conversation
lib/money/money.rb
Outdated
There was a problem hiding this comment.
I can see 2 issues around this:
- It's not thread-safe: if two threads call
Money.rounding_modethen you may get inconsistent results. - If the yield fails for any reason you may be left in an inconsistent state because you haven't set the rounding mode back. Suggest you use an
ensureto set the rounding mode back.
There was a problem hiding this comment.
Fair points, I was also thinking maybe rounding_mode should return yield results instead of the current rounding mode because when you are temporarily changing it getting back the current mode isn't really that useful but getting back the results of a calculation would be.
What would be the right way to make it thread safe?
|
Closing, please reopen if you're actively working on this. |
|
I'd like to work on it but I didn't get any other feedback about how best to make it thread safe. |
…ck returns the result when being passed a rounding mode
|
@ohthatjames do you have more suggestions? |
|
@semmons99 I've gone ahead and made changes in my branch that I think will make it thread safe. I can't seem to reopen the pull request though. |
|
Should I just create a new pull request? |
|
@hadees reopened |
|
I also want to update the YARD docs before this gets merged in but I'm not sure the right syntax to show it returns |
|
I believe you're looking for |
|
That was my last update to the branch unless anyone has more suggestions. |
|
looks good |
Adding ability to temporarily change the rounding mode
|
Really sorry, I've been away and I missed the notifications on this one. Two observations:
This is caused by 32929d8#diff-a6d34f32282d8d431a585cdaf0aaf730R174 - we may have to make it an array and push and pop rounding modes.
|
|
BTW, happy to look into the nested blocks issue if others think it's worth closing off. |
|
@ohthatjames it would be nice to have the nested blocks issue fixed, but I don't think it's something that's high priority. |
I added the ability to temporarily change the rounding mode in a block passed to
Money.rounding_mode. I needed this feature because I'm using Stripe as my payment processor and they use a different rounding mode then I am. So this makes it easier for me to estimate their fees.