Skip to content

Fix "method redefined" warnings for sum method#46

Merged
kou merged 5 commits intored-data-tools:masterfrom
kojix2:issue-43
Dec 24, 2025
Merged

Fix "method redefined" warnings for sum method#46
kou merged 5 commits intored-data-tools:masterfrom
kojix2:issue-43

Conversation

@kojix2
Copy link
Member

@kojix2 kojix2 commented Dec 24, 2025

Fixes #43

Hello.
This PR addresses the issue in #43.

  • Create an alias method __sum__ for Enumerable and Array.
  • Call the alias method internally.
  • Update the documentation.

@kojix2
Copy link
Member Author

kojix2 commented Dec 24, 2025

The reason we need to override the default sum method is to accept the skip_na keyword argument.
Updated README.md to clarify this.

Comment on lines 2533 to 2534
id_builtin_enum_sum = rb_intern("__builtin_sum");
id_builtin_ary_sum = rb_intern("__builtin_sum");
Copy link
Member

Choose a reason for hiding this comment

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

We can use one id_builtin_sum.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, same method name is fine here.

* to compensate the result precision when the `ary` includes Float values.
*
* Note that This library does not redefine `sum` method introduced in Ruby 2.4.
* Redefines `sum` (Ruby 2.4). Original is aliased as `__sum__`.
Copy link
Member

Choose a reason for hiding this comment

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

Let's use ASCII.

Suggested change
* Redefines `sum` (Ruby 2.4). Original is aliased as `__sum__`.
* Redefines `sum` (Ruby >= 2.4). Original is aliased as `__sum__`.

* to compensate the result precision when the `enum` includes Float values.
*
* Note that This library does not redefine `sum` method introduced in Ruby 2.4.
* Redefines `sum` (Ruby 2.4). Original is aliased as `__sum__`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Redefines `sum` (Ruby 2.4). Original is aliased as `__sum__`.
* Redefines `sum` (Ruby >= 2.4). Original is aliased as `__sum__`.

@kou kou merged commit 6cf5156 into red-data-tools:master Dec 24, 2025
25 of 27 checks passed
@kou
Copy link
Member

kou commented Dec 24, 2025

Thanks.

@kojix2 kojix2 deleted the issue-43 branch December 24, 2025 07:51
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.

warning: method redefined

2 participants