From: Robert Klemme Date: 2005-09-24T23:21:40+09:00 Subject: Re: self.puts? Derek Chesterfield wrote: > On 24 Sep 2005, at 12:47pm, Stefan Lang wrote: > >> On Saturday 24 September 2005 12:30, Derek Chesterfield wrote: >> >>> how come the >>> result of 'puts' is different to the result of 'self.puts'? >> >> Ruby doesn't allow that a private method is called with an explicit >> receiver. If you write "self.puts", "self" is an explicit receiver. >> If you simply write "puts" the receiver is implicitly "self". > > Ah - I knew it was semantics! Thanks for your explanation. It makes > perfect sense now: because it is a private method, you *shouldn't* > need to write it explicitly! This code also solidified it for me: > >> $ irb >> irb(main):001:0> module Kernel >> irb(main):002:1> public :puts >> irb(main):003:1> end >> => Kernel >> irb(main):004:0> puts "asd" >> asd >> => nil >> irb(main):005:0> self.puts "asd" >> asd >> => nil > > Thanks again! Note also that you can call private methods with send: self.send(:puts, "foo") Kind regards robert