зеркало из https://github.com/github/ruby.git
fix Struct's setter arity
https://github.com/ruby/ruby/pull/5131/files#diff-b2553d23e6b1fe76e20608d06c25f6acca06279100f1a9c24febcd79a82fac3cR2689
This commit is contained in:
Родитель
6659253cc6
Коммит
fdfb43b2b1
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;
|
return 0;
|
||||||
case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
|
case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
|
||||||
*max = 1;
|
*max = 1;
|
||||||
return 0;
|
return 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,6 +497,20 @@ module TestStruct
|
||||||
assert_equal(42, x.public_send("a"))
|
assert_equal(42, x.public_send("a"))
|
||||||
end
|
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
|
def test_parameters
|
||||||
klass = @Struct.new(:a)
|
klass = @Struct.new(:a)
|
||||||
assert_equal [], klass.instance_method(:a).parameters
|
assert_equal [], klass.instance_method(:a).parameters
|
||||||
|
|
Загрузка…
Ссылка в новой задаче