Skip to content

Add Money.with_bank for Dynamic Currency Stores #1145

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

Merged
merged 5 commits into from
Jul 23, 2025

Conversation

pranavbabu
Copy link
Contributor

After some #discussions with @yukideluxe it seems like this library is a better place for this #PR.

This PR introduces the Money.with_bank method, allowing developers to assign different currency stores (banks) dynamically within a scoped block. This is particularly useful for loading custom exchange rates per user session.

Key Changes

  • Implemented Money.with_bank(bank_instance), enabling temporary overrides of the default bank.
  • Ensures thread safety by restoring the original bank after execution.

Copy link
Contributor

@sunny sunny left a comment

Choose a reason for hiding this comment

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

Much better indeed, love the addition of the spec for thread-safety as well.

@sunny
Copy link
Contributor

sunny commented Jul 15, 2025

Can you add a CHANGELOG entry? 🙏🏻

Copy link
Contributor

@pawelma pawelma left a comment

Choose a reason for hiding this comment

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

I like the addition, left some comments, mostly nitpicky 😅

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

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

sorry the delay! thanks for all the changes! this gem uses rbs for typing the method. Would you mind adding that in a similar fashion to

# Temporarily changes the rounding mode in a given block.
#
# @param [BigDecimal::ROUND_MODE] mode
#
# @yield The block within which rounding mode will be changed. Its return
# value will also be the return value of the whole method.
#
# @return [Object] block results
#
# @example
# fee = Money.with_rounding_mode(BigDecimal::ROUND_HALF_DOWN) do
# Money.new(1200) * BigDecimal('0.029')
# end
def self.with_rounding_mode: (untyped mode) { () -> untyped } -> untyped

🙏🏻

last thing and I meeeergeeeee

@pranavbabu
Copy link
Contributor Author

@yukideluxe Lets hope I've done it right :D

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

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

looks good to me! thanks! 🙏🏻

@yukideluxe yukideluxe merged commit e833146 into RubyMoney:main Jul 23, 2025
6 checks passed
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.

4 participants