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

Allow to pass the method signature when defining attribute methods #41911

Merged
merged 2 commits into from
Apr 12, 2021

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Apr 11, 2021

This is mostly a rebase of #38356

This saves some array allocations from avoiding *args and is generally marginally faster. Actually it is over twice as fast.

It also makes the Method object arity and parameters correct.

e.g. before this patch, ArgumentError would be confusing:

>> model.name_was(1)
ArgumentError: wrong number of arguments (given 2, expected 1)

For backward compatibility reasons, the parameters list defaults to "*args".

This saves some array allocations from avoiding `*args`, as well
as makes the Method object `arity` and `parameters` correct.

e.g. before this patch, ArgumentError would be confusing:

```ruby
>> model.name_was(1)
ArgumentError: wrong number of arguments (given 2, expected 1)
```
@byroot byroot merged commit 6a5fb7d into rails:main Apr 12, 2021
alpaca-tc added a commit to alpaca-tc/active_record_bitmask that referenced this pull request Sep 29, 2021
In Rails 7.0.0, `#attribute?` with arguments doesn't work.
Because rails/rails#41911 introduced new behavior for attribute methods to raise exception when unnecessary arguments given. Therefore can't use `attribute?` for bitmask in Rails 7.0.0.

This changes are followings.
- Warn deprecation warning when using `attribute?` for bitmask attribute.
- Add `attribute_bitmask?` to support same behavior. This works fine in Rails 7.0.0.
alpaca-tc added a commit to alpaca-tc/active_record_bitmask that referenced this pull request Sep 29, 2021
In Rails 7.0.0, `#attribute?` with arguments doesn't work.
Because rails/rails#41911 introduced new behavior for attribute methods to raise exception when unnecessary arguments given. Therefore can't use `attribute?` for bitmask in Rails 7.0.0.

This changes are followings.
- Warn deprecation when using `attribute?` for bitmask attribute.
- Add `attribute_bitmask?` to support same behavior. This works fine in Rails 7.0.0.
alpaca-tc added a commit to alpaca-tc/active_record_bitmask that referenced this pull request Sep 29, 2021
In Rails 7.0.0, `#attribute?` with arguments doesn't work.
Because rails/rails#41911 introduced new behavior for attribute methods to raise exception when unnecessary arguments given. Therefore can't use `attribute?` for bitmask in Rails 7.0.0.

This changes are followings.
- Warn deprecation when using `attribute?` for bitmask attribute.
- Add `attribute_bitmask?` to support same behavior. This works fine in Rails 7.0.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants