summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-31 17:03:11 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-01 08:52:15 -0700
commitef45a57801a2ae8621b0cde59f11159f89f0a8dc (patch)
tree2b30a7ebea2497b1efc49cfc23d95f4e214a99ea /test/ruby
parentb8e351a1b9a16ce27f53d15051a1d1f83911b8cb (diff)
Make attr* methods define public methods if self in caller is not same as receiver
Previously, attr* methods could be private even if not in the private section of a class/module block. This uses the same approach that ruby started using for define_method in 1fc33199736f316dd71d0c551edbf514528ddde6. Fixes [Bug #4537]
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_module.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 37045ad0d9..cf50db3374 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -705,6 +705,32 @@ class TestModule < Test::Unit::TestCase
assert_equal(false, o.respond_to?(:bar=))
end
+ def test_attr_public_at_toplevel
+ s = Object.new
+ TOPLEVEL_BINDING.eval(<<-END).call(s.singleton_class)
+ proc do |c|
+ c.send(:attr_accessor, :x)
+ c.send(:attr, :y)
+ c.send(:attr_reader, :z)
+ c.send(:attr_writer, :w)
+ end
+ END
+ assert_nil s.x
+ s.x = 1
+ assert_equal 1, s.x
+
+ assert_nil s.y
+ s.instance_variable_set(:@y, 2)
+ assert_equal 2, s.y
+
+ assert_nil s.z
+ s.instance_variable_set(:@z, 3)
+ assert_equal 3, s.z
+
+ s.w = 4
+ assert_equal 4, s.instance_variable_get(:@w)
+ end
+
def test_const_get_evaled
c1 = Class.new
c2 = Class.new(c1)