Issue #4537 has been updated by Koichi Sasada.

Category set to core
Target version set to 1.9.x

Behavior: It inherits current visibility (visibility of top-level is "private").  1.8 also causes an exception.  It seems to be a spec.

However, the following code:

  ::String.send(:define_method, :x=){|v|}
  s = ''
  s.x = 100

doesn't cause an exception.  It seems to be an inconsistency.

The following code doesn't cause an exception on 1.9 and 1.8:

  class C
    private
    ::String.send(:define_method, :x=){|v|}
  end
  s = ''
  s.x = 100

However, the following code causes an exception only on 1.8:

  class C
    private
    define_method(:x=){|v|}
  end
  C.new.x = 10

I can't understand how should it be.

Possible solutions:

(1) Remain it as spec.

(2) All "attr_*" methods define all methods in public.

(3) others?


----------------------------------------
Bug #4537: Incorrectly creating private method via attr_accessor
http://redmine.ruby-lang.org/issues/4537

Author: Ryan LeCompte
Status: Assigned
Priority: Normal
Assignee: Koichi Sasada
Category: core
Target version: 1.9.x
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30907) [x86_64-darwin10.7.0]


# The following fails with a failure to call "x=" private method
String.send(:attr_accessor, :x)
s = ""
s.x = 100

# The following works:
class String
  self.send(:attr_accessor, :x)
end
s = ""
s.x = 100


-- 
http://redmine.ruby-lang.org