Commit 7bf1cd5
committed
Fix(Entity): Improve block arity detection for
Addresses `ArgumentError`s when using `&:method_name` with `expose`,
a scenario particularly affected by Ruby 3.0's stricter argument handling
for procs. The previous arity check, including the condition
`block.parameters == [[:req], [:rest]]`, was not consistently reliable
for these cases.
This change introduces `determine_block_arity` which:
1. Attempts to parse the original method name from `Proc#to_s` for
blocks likely created via `&:method_name`.
2. If the method name is found and the object responds to it, this
logic uses the *actual arity of the original method* to correctly
determine how `instance_exec` should be called.
3. If the original method name can't be determined, it falls back
to using `block.parameters.size`.
This ensures methods exposed via `&:method_name` are called with the
correct arguments (i.e., with or without `options`), resolving the
`ArgumentError`s and removing the need for the previous `rescue` logic.Symbol#to_proc
1 parent c8f7a22 commit 7bf1cd5
2 files changed
Lines changed: 23 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
521 | 533 | | |
522 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
523 | 537 | | |
524 | 538 | | |
525 | 539 | | |
526 | 540 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | 541 | | |
537 | 542 | | |
538 | 543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
442 | 429 | | |
443 | | - | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
444 | 433 | | |
445 | | - | |
446 | | - | |
447 | | - | |
| 434 | + | |
| 435 | + | |
448 | 436 | | |
449 | 437 | | |
450 | 438 | | |
| |||
0 commit comments