Allow subclassing money #544

Merged
merged 3 commits into from Jul 27, 2015

Projects

None yet

4 participants

@nilbus
Contributor
nilbus commented Jul 27, 2015

I can see from the spec previously included that it was desired that subclassing would work, but the implementation was incomplete.

Scenario:

class SpecialMoney < Money
  # ...
end

SpecialMoney.new(val1) + SpecialMoney.new(val2)
# => returns Money instead of SpecialMoney, thus losing the
# SpecialMoney extensions.

All specs remain green, and it works as expected. New specs have been added to attempt to prevent regression.

nilbus added some commits Jul 27, 2015
@nilbus nilbus Support subclassing of Money by never instantiating it by name
Scenario:

    class SpecialMoney < Money
      # ...
    end

    SpecialMoney.new(val1) + SpecialMoney.new(val2)
    # => returns Money instead of SpecialMoney, thus losing the
    # SpecialMoney extensions.
6abbc40
@nilbus nilbus Report the actual class in Money#inspect
Currency#inspect is also defined but already does this.
a914520
@nilbus nilbus Expand inheritance tests to all the methods that handle it
Method calls on a subclass of Money should never return a Money object.
df7b41e
@josephjaber

👍

@semmons99
Member

nice!

@semmons99 semmons99 merged commit 6655a38 into RubyMoney:master Jul 27, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@nilbus
Contributor
nilbus commented Jul 27, 2015

Thanks for the quick response! If you could release this quickly, that would be helpful to myself and @josephjaber. I believe this would qualify as a patch release (6.6.1), as it seems like a fix to something that was already intended. What do you think?

@semmons99
Member

6.6.1 released

@nilbus
Contributor
nilbus commented Jul 27, 2015

Thanks Shane!​

@Funfun
Member
Funfun commented Jul 30, 2015

nice patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment