Women in Technology

Hear us Roar

Subject:   Using Ruby
Date:   2004-06-28 11:24:35
From:   christopher_roach
Response to: Using Ruby

I'm sorry about the problem you had with the line endings. I nearly always use the Unix line endings so it never occured to me to warn others against using another type.

As for the problem your having with the call to self.puts, well that is occuring because of the way that Ruby handles access control. In the kernel module all of the methods are declared private. 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 a sample class to prove my point.

class MyClass
def sayHello()

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

myClass = MyClass.new()

Try running it at the command line. You should get an error similar to the puts error you received. If you remove the reference to self or if you remove the 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.