Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class Test
  2. def self.public_method
  3. "Hello from public"
  4. end
  5.  
  6. protected
  7.  
  8. def self.protected_method
  9. "Hello from 'supposted' protected method"
  10. end
  11.  
  12. private
  13.  
  14. def self.private_method
  15. "Hello from 'supposted' private method"
  16. end
  17.  
  18. class << self
  19. protected
  20.  
  21. def real_protected_method
  22. "Hello from real protected method"
  23. end
  24.  
  25. private
  26.  
  27. def real_private_method
  28. "Hello from real private method"
  29. end
  30. end
  31. end
  32.  
  33. # Test.public_method
  34. # Test.protected_method
  35. # Test.private_method
  36. # Test.real_protected_method
  37. # Test.real_private_method
  38.  
  39. ruby-1.8.7-p249 > Test.public_method
  40. => "Hello from public"
  41. ruby-1.8.7-p249 > Test.protected_method
  42. => "Hello from 'supposted' protected method"
  43. ruby-1.8.7-p249 > Test.private_method
  44. => "Hello from 'supposted' private method"
  45. ruby-1.8.7-p249 > Test.real_protected_method
  46. NoMethodError: protected method `real_protected_method' called for Test:Class
  47. ruby-1.8.7-p249 > Test.real_private_method
  48. NoMethodError: private method `real_private_method' called for Test:Class
Add Comment
Please, Sign In to add comment