Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment