Created
April 23, 2014 18:07
-
-
Save davidcornu/11226503 to your computer and use it in GitHub Desktop.
Ruby self.private_method vs private_method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
def foo | |
puts baz | |
end | |
def bar | |
puts self.baz | |
end | |
private | |
def baz | |
"baz" | |
end | |
end | |
my_class = MyClass.new | |
my_class.foo | |
my_class.bar | |
# ---- Output ---- | |
# baz | |
# test.rb:10:in `bar': private method `baz' called for #<MyClass:0x007fb413082810> (NoMethodError) | |
# from test.rb:24:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment