Skip to content

Conversation

@tob1k
Copy link

@tob1k tob1k commented Nov 20, 2025

Fixes the long-standing issue where using Symbol#to_proc syntax (e.g., field :name, &:first_name) would raise an ArgumentError.

Problem:

BlockExtractor was calling all blocks with 2 arguments: block.call(object, local_options). Symbol#to_proc forwards ALL arguments to the target method, causing it to call object.method_name(local_options), which fails when methods don't accept extra arguments.

Solution:

Detect Symbol#to_proc by its characteristic parameter signature [[:req], [:rest]] and call it with only the object argument, while regular blocks continue to receive both arguments.

Benefits:

  • Enables cleaner, more idiomatic Ruby syntax
  • Eliminates need for rubocop disable comments
  • Maintains full backward compatibility with existing code
  • No breaking changes to API

Related: rubocop/rubocop#8201

Checklist:

  • I have updated the necessary documentation
  • I have signed off all my commits as required by DCO
  • My build is green

Fixes the long-standing issue where using Symbol#to_proc syntax
(e.g., `field :name, &:first_name`) would raise an ArgumentError.

**Problem:**
BlockExtractor was calling all blocks with 2 arguments:
`block.call(object, local_options)`. Symbol#to_proc forwards ALL
arguments to the target method, causing it to call
`object.method_name(local_options)`, which fails when methods
don't accept extra arguments.

**Solution:**
Detect Symbol#to_proc by its characteristic parameter signature
`[[:req], [:rest]]` and call it with only the object argument,
while regular blocks continue to receive both arguments.

**Benefits:**
- Enables cleaner, more idiomatic Ruby syntax
- Eliminates need for rubocop disable comments
- Maintains full backward compatibility with existing code
- No breaking changes to API

Related: rubocop/rubocop#8201

Signed-off-by: Tobias Carvan <[email protected]>
@tob1k tob1k requested review from a team and ritikesh as code owners November 20, 2025 00:03
@bibek-khadka
Copy link

+1

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.

2 participants