Issue #4537 has been updated by nobu (Nobuyoshi Nakada).

Description updated

Seems fine.

BTW, it doesn't need to be the global `String`.

```diff
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index cdc084c8bc..9e57692ca0 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -706,13 +706,16 @@
   end
 
   def test_attr_public_at_toplevel
-    eval(<<-END, TOPLEVEL_BINDING)
-      String.send(:attr_accessor, :x)
-      String.send(:attr, :y)
-      String.send(:attr_reader, :z)
-      String.send(:attr_writer, :w)
+    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
-    s = ""
+
     assert_nil s.x
     s.x = 1
     assert_equal 1, s.x
@@ -727,10 +730,6 @@
 
     s.w = 4
     assert_equal 4, s.instance_variable_get(:@w)
-  ensure
-    [:x, :x=, :y, :z, :w=].each do |meth|
-      String.undef_method(meth) rescue nil
-    end
   end
 
   def test_const_get_evaled
```

----------------------------------------
Bug #4537: Incorrectly creating private method via attr_accessor
https://bugs.ruby-lang.org/issues/4537#change-80325

* Author: ryanlecompte (Ryan LeCompte)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
The following fails with a failure to call "`x=`" private method

```ruby
String.send(:attr_accessor, :x)
s = ""
s.x = 100
```

The following works:

```ruby
class String
  self.send(:attr_accessor, :x)
end
s = ""
s.x = 100
```


---Files--------------------------------
attr-visibility-4537.patch (2.75 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>