Created
April 13, 2020 16:45
-
-
Save koriroys/6b59bec8713ef0de4e42bf5f3195c960 to your computer and use it in GitHub Desktop.
Why does this happen?
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 Thing | |
class << self | |
def public_method | |
private_method | |
end | |
private | |
def private_method | |
"hello" | |
end | |
end | |
end | |
Thing.public_method # => "hello" | |
class Thing2 | |
class << self | |
def public_method | |
self.private_method | |
end | |
private | |
def private_method | |
"hello" | |
end | |
end | |
end | |
Thing2.public_method # => NoMethodError (private method `private_method' called for Thing2:Class) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment