From 6659253cc6c807641e23d469b425ddcf18de7af4 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Mon, 13 Dec 2021 01:58:21 +0900 Subject: Struct setter's parameters == `[:req, :_]` fix [Bug #18405] Note that the parameter name `_` is not a spec, so we shouldn't rely on this behavior. --- test/ruby/test_struct.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 0301612395..b0e6bae9e3 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -497,6 +497,21 @@ module TestStruct assert_equal(42, x.public_send("a")) end + def test_parameters + klass = @Struct.new(:a) + assert_equal [], klass.instance_method(:a).parameters + # NOTE: :_ may not be a spec. + assert_equal [[:req, :_]], klass.instance_method(:a=).parameters + + klass.module_eval do + define_method(:b=, &klass.new.method(:a=).to_proc) + alias c= a= + end + + assert_equal [[:req, :_]], klass.instance_method(:b=).parameters + assert_equal [[:req, :_]], klass.instance_method(:c=).parameters + end + class TopStruct < Test::Unit::TestCase include TestStruct -- cgit v1.2.3