From: Robert Klemme Date: 2011-11-24T00:04:12+09:00 Subject: Re: private and protected On Wed, Nov 23, 2011 at 3:08 PM, Peter Hickman wrote: > The call 'self.phrase' is a call to a class method I am sorry, this is wrong. A class method would be called with "self.class.phrase". "self.phrase" attempts to invoke an instance method. > but 'def phrase' is > the definition of an instance method. Either remove the self in the > say method or change 'def phrase' to 'def self.phrase'. > > It has nothing to do with private or protected. It has: irb(main):001:0> class First irb(main):002:1> def say_1; self.phrase; end irb(main):003:1> def say_2; phrase; end irb(main):004:1> private irb(main):005:1> def phrase;"ph";end irb(main):006:1> end => nil irb(main):007:0> f = First.new => # irb(main):008:0> f.say_1 NoMethodError: private method `phrase' called for # from (irb):2:in `say_1' from (irb):8 from /opt/bin/irb19:12:in `
' irb(main):009:0> f.say_2 => "ph" See Daniel's explanation. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/