[ruby-core:63852] [ruby-trunk - Bug #10060] [Closed] private attr_accessor and NoMethodError

From: nobu@...
Date: 2014-07-19 03:41:02 UTC
List: ruby-core #63852
Issue #10060 has been updated by Nobuyoshi Nakada.

Status changed from Open to Closed
% Done changed from 0 to 100

Applied in changeset r46873.

----------
compile.c: private reader in op_assign

* compile.c (iseq_compile_each): allow to access private attribute
  reader in op_assign.  [ruby-core:63817] [Bug #10060]

----------------------------------------
Bug #10060: private attr_accessor and NoMethodError
https://bugs.ruby-lang.org/issues/10060#change-47882

* Author: John Doe
* Status: Closed
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
~~~ruby
class Bug
  def initialize
    self.n = 1 # ok
  end

  def t1
    self.n = n + 1 # ok
    self.n += 1 # in `t1': private method `n' called for #<Bug:0x000000019ae1a0 @n=2> (NoMethodError)
  end

  def t2
    n # ok
    self.n # in `t2': private method `n' called for #<Bug:0x0000000218a360 @n=1> (NoMethodError)
  end

  private

  attr_accessor :n
end
~~~



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

In This Thread

Prev Next