Ruby Conditional-Assignment and Private Methods

前端 未结 1 1630
情话喂你
情话喂你 2021-01-02 02:04

From the code below, it appears the ||= operator is being evaluated from outside of the class.

class Foo
  attr_reader :bar

  def baz
    self.         


        
相关标签:
1条回答
  • 2021-01-02 02:46

    That looks like a bug.

    UPDATE: The bug was fixed in trunk, and is slated for back porting to 2.1 and 2.0.

    Note that the problem is more general than that, it is broken for all abbreviated assignments, not just conditional abbreviated assignments:

    private def foo=(*) end
    public  def foo; 0  end
    
    self.foo =  42
    
    self.foo += 42
    # private method `foo=' called for main:Object (NoMethodError)
    
    private :foo
    
    self.foo += 42
    # private method `foo' called for main:Object (NoMethodError)
    
    0 讨论(0)
提交回复
热议问题