From: americodls@... Date: 2017-05-23T14:43:58+00:00 Subject: [ruby-core:81351] [Ruby trunk Bug#13592] Enumerable#reduce with symbol does not respect method visibility Issue #13592 has been updated by americodls (Americo Duarte). Sorry, ignore the IRB thing. But my question about the reduce still valid. americodls (Americo Duarte) wrote: > When use reduce with symbol, I expect the symbol is called in object but respecting the method visibility. > > Example with source code written in a file. > > ~~~ > Fixnum.instance_eval do > private :+ > end > > p [1,2,3].reduce(:+) > ~~~ > > The behavior in IRB is different. > > ~~~ > irb(main):001:0> [1,2,3].reduce(:+) > => 6 > irb(main):002:0> Fixnum.instance_eval do > irb(main):003:1* private :+ > irb(main):004:1> end > => Fixnum > irb(main):005:0> > /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/input-method.rb:154:in `gets': private method `+' called for 4:Fixnum (NoMethodError) > ~~~ > > Now, I am confused. Those behaviors are expected? In doc this is not clear. ---------------------------------------- Bug #13592: Enumerable#reduce with symbol does not respect method visibility https://bugs.ruby-lang.org/issues/13592#change-65047 * Author: americodls (Americo Duarte) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- When use reduce with symbol, I expect the symbol is called in object but respecting the method visibility. Example with source code written in a file. ~~~ Fixnum.instance_eval do private :+ end p [1,2,3].reduce(:+) ~~~ The behavior in IRB is different. ~~~ irb(main):001:0> [1,2,3].reduce(:+) => 6 irb(main):002:0> Fixnum.instance_eval do irb(main):003:1* private :+ irb(main):004:1> end => Fixnum irb(main):005:0> /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/input-method.rb:154:in `gets': private method `+' called for 4:Fixnum (NoMethodError) ~~~ Now, I am confused. Those behaviors are expected? In doc this is not clear. -- https://bugs.ruby-lang.org/ Unsubscribe: