Created
October 11, 2017 17:34
-
-
Save arthur-littm/00de8cc1506b22da5c269ffdf8fabe86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FacebookUser | |
# DATA (instance variables) | |
attr_reader :email, :friends, :photos | |
attr_accessor :first_name, :last_name | |
def initialize(email, password) # constructor | |
@email = email | |
@password = password | |
@first_name = "" | |
@last_name = "" | |
@friends = [] | |
@photos = [] | |
end | |
# BEHAVIOR (instance methods) | |
def password | |
return "*******" | |
end | |
def password_checker?(old_password) | |
@password == old_password | |
end | |
def password_changer(new_password) | |
@password = new_password | |
end | |
def to_s | |
"name: #{first_name + " " + last_name} email: #{email} password: #{password} number of friends:#{friends.count} number of photos:#{photos.count}" | |
end | |
def add_photo(url) | |
@photos << url | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "facebook_user" | |
# SCENARIO 1 - Create a new user (+ FacebookUser#to_s) | |
puts "welcome to facebook!" | |
puts "---" | |
puts "enter your email address" | |
email = "arthur@lewagon.com" | |
puts "---" | |
puts "enter your password" | |
password = "password" | |
puts "---" | |
first_user = FacebookUser.new(email, password) | |
puts first_user | |
# SCENARIO 2 - Update details of user | |
first_user.first_name = "Arthur" | |
first_user.last_name = "Littmann" | |
puts "---" | |
puts first_user | |
# SCENARIO 3 - Add a new photo | |
first_user.add_photo("url") | |
puts "---" | |
puts first_user | |
# SCENARIO 4 - Change password | |
old_password = "" | |
p first_user | |
until first_user.password_checker?(old_password) | |
puts "What's your old password" | |
old_password = gets.chomp | |
if first_user.password_checker?(old_password) | |
puts "What's your new password" | |
new_password = gets.chomp | |
first_user.password_changer(new_password) | |
old_password = new_password | |
else | |
puts "dummy try again" | |
end | |
end | |
p first_user | |
# SCENARIO 5 - Add a new friend | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment