Guest User

Untitled

a guest
Aug 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class Foo
  2. def m1
  3. puts "private"
  4. end
  5.  
  6. def m2
  7. puts "protected"
  8. end
  9.  
  10. private :m1
  11. protected :m2
  12.  
  13. def m3 #Private and Proteceted can be invoked indirectly like this thorough a function
  14. m1
  15. m2
  16. end
  17.  
  18. def m4 #Protected can be invoked thorough a reciever
  19. m2
  20. self.m2
  21. Foo.new.m2
  22. end
  23.  
  24. def m5 # Private cannot have reciever so self.m1 and Foo.new.m1 will throw error
  25. m1
  26. end
  27. end
Add Comment
Please, Sign In to add comment