mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
fix Struct's setter arity
https://github.com/ruby/ruby/pull/5131/files#diff-b2553d23e6b1fe76e20608d06c25f6acca06279100f1a9c24febcd79a82fac3cR2689
This commit is contained in:
parent
6659253cc6
commit
fdfb43b2b1
Notes:
git
2021-12-13 10:24:23 +09:00
2 changed files with 15 additions and 1 deletions
2
proc.c
2
proc.c
|
@ -2684,7 +2684,7 @@ method_def_min_max_arity(const rb_method_definition_t *def, int *max)
|
|||
return 0;
|
||||
case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
|
||||
*max = 1;
|
||||
return 0;
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -497,6 +497,20 @@ module TestStruct
|
|||
assert_equal(42, x.public_send("a"))
|
||||
end
|
||||
|
||||
def test_arity
|
||||
klass = @Struct.new(:a)
|
||||
assert_equal 0, klass.instance_method(:a).arity
|
||||
assert_equal 1, klass.instance_method(:a=).arity
|
||||
|
||||
klass.module_eval do
|
||||
define_method(:b=, &klass.new.method(:a=).to_proc)
|
||||
alias c= a=
|
||||
end
|
||||
|
||||
assert_equal 1, klass.instance_method(:b=).arity
|
||||
assert_equal 1, klass.instance_method(:c=).arity
|
||||
end
|
||||
|
||||
def test_parameters
|
||||
klass = @Struct.new(:a)
|
||||
assert_equal [], klass.instance_method(:a).parameters
|
||||
|
|
Loading…
Add table
Reference in a new issue