update signature | Money#nonzero? returns nil or BigDecimal#337
update signature | Money#nonzero? returns nil or BigDecimal#337jparker wants to merge 1 commit intoShopify:mainfrom
Money#nonzero? returns nil or BigDecimal#337Conversation
``` irb(main):002> Money.new(0, 'USD').nonzero?.class => NilClass irb(main):003> Money.new(1, 'USD').nonzero?.class => BigDecimal ``` * https://docs.ruby-lang.org/en/3.2/BigDecimal.html#method-i-nonzero-3F * https://ruby-doc.org/3.4/gems/bigdecimal/BigDecimal.html#method-i-nonzero-3F
|
I have signed the CLA! |
|
Hey John! I'm a bit torn on what to do here. This is also a breaking change to make: Sorbet.run Can you please share an example use-case that uses the result value of this as a big decimal, rather than just using its truthiness/falsiness to treat is like a boolean? |
To be honest, I can't. I generally only ever use this predicate in a context where returning a boolean makes the most logical sense. I only noticed the problem in practice because I had adapt a signature in some application code that could return the result of Other Numeric classes implement similar behavior for EDIT: Maybe an alternative is for Money itself to implement the method directly with a truly Boolean return value rather than delegating? There is one inconsistency in that it returns the underlying BigDecimal and not self. |
Updates the signature for
Money#nonzero?to returnT.nilable(BigDecimal)instead ofT::Boolean. Money delegates#nonzero?to the underlying value, stored as aBigDecimalwhich returns eithernilorself.Type of Change
Changes