Ruby/Tk Primer: Creating a cron GUI Interface with Ruby/Tk
Subject:   Answer to the self.puts dilema
Date:   2004-06-28 18:40:32
From:   christopher_roach

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.

class MyClass
def sayHello()

def hello()
puts "Hello, World!!!"

myClass =

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.

1 to 2 of 2
  1. Answer to the self.puts dilema
    2004-07-19 18:23:49 [View]

  2. Answer to the self.puts dilema
    2004-07-19 16:12:40  Merc [View]

    • Answer to the self.puts dilema
      2004-07-19 20:30:53  Christopher Roach | O'Reilly Blogger [View]

    • Answer to the self.puts dilema
      2004-07-19 16:18:43  Merc [View]

1 to 2 of 2