Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Implement encapsulation to achieve the following
- # You want to post on facebook to say:
- # "hello world" visible to everyone
- # "hello friends" visible only to your friends
- # "hello new people" visible only to friends of friends
- # create class FbPost and User
- # FbPost should include methods to print posts like "hello world" etc
- class FbPost
- def user_msg_everyone
- puts "hello world"
- end
- private
- def msg_to_friends(message)
- puts message
- end
- protected
- def msg_friends_of_friends(message)
- puts message
- end
- end
- class User < FbPost
- def access_msg
- msg_to_friends("hello friends")
- FbPost.new.msg_friends_of_friends("hello new friends")
- end
- end
- # user = FbPost.new
- # user.user_msg_everyone
- users = User.new
- users.user_msg_everyone
- users.access_msg
Add Comment
Please, Sign In to add comment