Guest User

Untitled

a guest
Apr 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # 1. Implement encapsulation to achieve the following
  2. # You want to post on facebook to say:
  3. # "hello world" visible to everyone
  4. # "hello friends" visible only to your friends
  5. # "hello new people" visible only to friends of friends
  6. # create class FbPost and User
  7. # FbPost should include methods to print posts like "hello world" etc
  8.  
  9. class FbPost
  10. def user_msg_everyone
  11. puts "hello world"
  12. end
  13. private
  14. def msg_to_friends(message)
  15. puts message
  16. end
  17. protected
  18. def msg_friends_of_friends(message)
  19. puts message
  20. end
  21. end
  22. class User < FbPost
  23. def access_msg
  24. msg_to_friends("hello friends")
  25. FbPost.new.msg_friends_of_friends("hello new friends")
  26. end
  27. end
  28. # user = FbPost.new
  29. # user.user_msg_everyone
  30. users = User.new
  31. users.user_msg_everyone
  32. users.access_msg
Add Comment
Please, Sign In to add comment