[ruby-core:96120] [Ruby master Bug#16403] Unavailable protected methods through `Symbol#to_proc`

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.issue-16403.20191205133408.dc296a3245c79df6@ruby-lang.org>
Issue #16403 has been reported by AlexWayfer (Alexander Popov).

----------------------------------------
Bug #16403: Unavailable protected methods through `Symbol#to_proc`
https://bugs.ruby-lang.org/issues/16403

* Author: AlexWayfer (Alexander Popov)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello!

I've faced with a bug (I guess):

``` ruby
# protected.rb
# frozen_string_literal: true

class Foo
  def initialize(text, *children)
    @text = text
    @children = children
  end

  def via_each
    @children.reduce(text) do |result, child|
      result + child.text
    end
  end

  def via_map
    text + @children.map(&:text).reduce(:+)
  end

  protected

  attr_reader :text
end

child1 = Foo.new('Alexander ')
child2 = Foo.new('Popov')

foo = Foo.new('Hello ', child1, child2)

puts foo.via_each

puts foo.via_map
```

Output:

```
Hello Alexander Popov
Traceback (most recent call last):
	2: from protected.rb:31:in `<main>'
	1: from protected.rb:16:in `via_map'
protected.rb:16:in `map': protected method `text' called for #<Foo:0x000055db24b97710 @text="Alexander ", @children=[]> (NoMethodError)
```




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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.