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

Support Complex and BigDecimal for Date#{+,-} #830

Merged
merged 1 commit into from
Dec 1, 2021
Merged

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented Nov 20, 2021

Date#{+,-} allows to pass an object with numeric argument and to_r method.

https://github.com/ruby/ruby/blob/6d540c1b9844a5832846618b53ce35d12d64deac/ext/date/date_core.c#L5785-L5786

For example, Complex and BigDecimal can be passed.

Date.today + Complex(1, 0)
#=> Date

Date.today + BigDecimal("1")
#=> Date

To achieve this behavior, the _ToR interface was introduced.

And Integer, Rational, and even Float are removed because they satisfy the condition of (Numeric & _ToR).

Date#{+,-} allows to pass an object with numeric argument and `to_r` method.
For example, Complex and BigDecimal can be passed.
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

Interesting! 👏 👏

@soutaro soutaro merged commit 521b3d0 into ruby:master Dec 1, 2021
@ksss ksss deleted the date branch December 3, 2021 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants