Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosantoniodasilva/468840 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/468840 to your computer and use it in GitHub Desktop.
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