Skip to content

Instantly share code, notes, and snippets.

@itstommymorgan
Created August 17, 2009 19:11
Show Gist options
  • Save itstommymorgan/169311 to your computer and use it in GitHub Desktop.
Save itstommymorgan/169311 to your computer and use it in GitHub Desktop.
## What I'm talking about.
class TestClass
# calling instance methods (public or private) works just fine
# if you don't use an explicit self.
def this_method_works_fine
foo
end
# calling instance methods with an explicit self is also fine,
# and required by the coding standards at my current job.
def this_method_also_works_fine
self.this_method_works_fine
end
# Calling private instance methods, however, will *not* work
# if you give it an explicit self. This is what I don't understand,
# and honestly seems somewhat arbitrary.
def this_method_does_not_work
self.foo
end
private
def foo
puts "Hoo-ah."
end
end
t = TestClass.new
t.this_method_works_fine #=> "Hoo-ah."
t.this_method_also_works_fine #=> "Hoo-ah."
t.this_method_does_not_work #=> breaks; "Private method foo called for class TestClass"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment