private and self

M

Marinho Tobolla

Why doesn´t the call with self doesn´t work ? I know that private means
private to the object, but the private methode call is within the same
object (at least it´s what i think). Doesn´t self mean "the object
himself" ? So why is this error occuring ?

test.rb:14:in `with_self': private method `private_methode' called for
#<PrivateTest:0x2aaaaab00508> (NoMethodError)

Code:
class PrivateTest

def private_methode()
puts("I am private")
end

def without_self()
puts("without self")
private_methode()
end

def with_self()
puts("with self")
self.private_methode()
end

private :private_methode
end

test = PrivateTest.new
test.without_self()
test.with_self()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top