Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2012 00:52
Show Gist options
  • Save anonymous/4290078 to your computer and use it in GitHub Desktop.
Save anonymous/4290078 to your computer and use it in GitHub Desktop.
I'm reading MetaProgramming Ruby by The Pragmatic Programmers and I'm very confused about private methods.
On page 55 he says "you cannot call a private method with an explicit receiver. In other words, every time you call a private method, it must be on the implicit receiver—self."
Then he gives this example:
class C
def public_method
self.private_method
end
private
def private_method; end
end
C.new.public_method
=> NoMethodError: private method ‘private_method' called [...]
So he says you can only call private methods with self, and then gives an example of that not working...???
He even says right after "You can make this code work by removing the self keyword."
But he just said "it must be on the implicit receiver—self."!!!
Am I going crazy? What do I not understand?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment