Created
July 9, 2010 00:16
-
-
Save carlosantoniodasilva/468840 to your computer and use it in GitHub Desktop.
This file contains 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 Test | |
def self.public_method | |
"Hello from public" | |
end | |
protected | |
def self.protected_method | |
"Hello from 'supposted' protected method" | |
end | |
private | |
def self.private_method | |
"Hello from 'supposted' private method" | |
end | |
class << self | |
protected | |
def real_protected_method | |
"Hello from real protected method" | |
end | |
private | |
def real_private_method | |
"Hello from real private method" | |
end | |
end | |
end | |
# Test.public_method | |
# Test.protected_method | |
# Test.private_method | |
# Test.real_protected_method | |
# Test.real_private_method | |
ruby-1.8.7-p249 > Test.public_method | |
=> "Hello from public" | |
ruby-1.8.7-p249 > Test.protected_method | |
=> "Hello from 'supposted' protected method" | |
ruby-1.8.7-p249 > Test.private_method | |
=> "Hello from 'supposted' private method" | |
ruby-1.8.7-p249 > Test.real_protected_method | |
NoMethodError: protected method `real_protected_method' called for Test:Class | |
ruby-1.8.7-p249 > Test.real_private_method | |
NoMethodError: private method `real_private_method' called for Test:Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment