Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created April 23, 2014 18:07
Show Gist options
  • Save davidcornu/11226503 to your computer and use it in GitHub Desktop.
Save davidcornu/11226503 to your computer and use it in GitHub Desktop.
Ruby self.private_method vs private_method
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