summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-12-13 01:58:21 +0900
committerKoichi Sasada <ko1@atdot.net>2021-12-13 10:23:52 +0900
commit6659253cc6c807641e23d469b425ddcf18de7af4 (patch)
tree0fb1ac56a26c1c045bec12965b6ebdabab58ce9c /test/ruby
parent4d0cb1a54ba5e8e053e6acc860fd1cb9ca5e1b19 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5252
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_struct.rb15
1 files changed, 15 insertions, 0 deletions
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