||Ruby/Tk Primer: Creating a cron GUI Interface with Ruby/Tk|
|Subject:||Answer to the self.puts dilema|
I seem to be having a problem figuring out the posting mechanism here. I posted a reply to the earlier message, but so far I can only view it by clicking on the View link. So rather than trying another reply, I thought I would try making a normal post and hope for the best.
As for the problem your with the call to self.puts, aturley, you are correct. The puts method is a private method of the kernel module included in the main object, and thus, its methods are mixed-in (Ruby's way of implementing multiple inheritance) to the main object. The problem arises in how Ruby handles private methods. In Ruby, private methods cannot be called with an explicit receiver (this includes the self reference). So when you try to prepend the reference to self to the puts call you get a private method error.
I included the following sample class to prove my point.
Try running it at the command line. You should get an error similar to the error you received when calling self.puts. If you remove private access modifier before the hello declaration, the program should execute properly.
I hope this staightens things out for you. One of the problems I have had with Ruby is fully understanding its access levels.
Thanks for the post.
Showing messages 1 through 5 of 5.
Answer to the self.puts dilema
2004-07-19 18:23:49 email@example.com [View]