Created
October 12, 2017 09:52
-
-
Save arthur-littm/ab90d89b2a6d5b6a8863b8006dd8b09b 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 Chef | |
attr_reader :name, :restaurant | |
def initialize(name, restaurant) | |
@name = name # String | |
@restaurant = restaurant # Restaurant | |
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 'restaurant' | |
require_relative 'gastronomic_restaurant' | |
nandos = Restaurant.new("Nandos", 100, "chicken", "London", "Jamie Oliver") | |
# puts "The chef of #{nandos.name} is #{nandos.chef.name}" | |
# Class method: | |
Restaurant.categories | |
# Instance method: | |
nandos.name | |
# SELF: | |
jamie = nandos.chef | |
# puts jamie.class | |
p jamie.restaurant |
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 add_friend(friend) | |
@friends << friend | |
friend.friends << self | |
end | |
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 'restaurant' | |
class FastfoodRestaurant < Restaurant | |
def initialize(name, capacity, category, city, preparation_time) | |
super(name, capacity, category, city) | |
@preparation_time = preparation_time | |
end | |
def open? | |
super() || (Time.now.hour >= 11 && Time.now.hour <= 17) | |
end | |
def print_clients | |
puts "There's no point for this" | |
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 'restaurant' | |
class GastronomicRestaurant < Restaurant | |
def initialize(name, capacity, category, city, stars) | |
super(name, capacity, category, city) | |
@stars = stars | |
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 "gastronomic_restaurant" | |
require_relative "fastfood_restaurant" | |
noma = GastronomicRestaurant.new("Noma", 200, "pretentious", "London", 2) | |
mcdonalds = FastfoodRestaurant.new("McDonalds", 300, "burger", "London", 5) | |
p noma | |
p mcdonalds | |
puts "#{noma.name} is now #{noma.open? ? 'open' : 'closed'}" | |
puts "#{mcdonalds.name} is now #{mcdonalds.open? ? 'open' : 'closed'}" | |
noma.book("Alex") | |
noma.book("Sandrine") | |
noma.book("Edward") | |
mcdonalds.book("Leonard") | |
puts noma.name | |
noma.print_clients | |
puts mcdonalds.name | |
mcdonalds.print_clients |
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" | |
puts "welcome to facebook!" | |
puts "---" | |
email = "arthur@lewagon.com" | |
password = "password" | |
arthur = FacebookUser.new(email, password) | |
puts arthur | |
alex = FacebookUser.new("alex@lewagon.com", "password") | |
puts alex | |
# SCENARIO 5 - Add a new friend | |
puts "---" | |
arthur.add_friend(alex) | |
puts arthur | |
puts alex | |
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 'restaurant' | |
# OBJECT ORIENTED PROGAMMING | |
nandos = Restaurant.new("Nandos", 100, "chicken", "London") | |
puts "#{nandos.name} is in #{nandos.city}" | |
puts "#{nandos.name} can hold #{nandos.capacity} people" | |
puts "Construction work happening..." | |
nandos.capacity = 150 | |
puts "#{nandos.name} can now hold #{nandos.capacity} people" | |
puts "#{nandos.name} is now #{nandos.open? ? 'open' : 'closed'}" | |
nandos.book("Alex") | |
nandos.book("Arthur") | |
nandos.book("Edward") | |
nandos.print_clients | |
# |
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 "chef" | |
class Restaurant | |
# DATA (instance variables) | |
attr_reader :name, :city, :chef | |
attr_accessor :capacity | |
def initialize(name, capacity, category, city, chef_name) | |
@name = name | |
@capacity = capacity | |
@category = category | |
@city = city | |
@chef = Chef.new(chef_name, self) # Chef | |
@clients = [] | |
end | |
# BEHAVIOR (instance methods) | |
def open? | |
Time.now.hour >= 18 && Time.now.hour <= 22 | |
end | |
def book(client_name) | |
@clients << client_name | |
end | |
def print_clients | |
@clients.each do |client| | |
puts "- #{client}" | |
end | |
end | |
# CLASS METHODS | |
def self.categories | |
["Luxurious", "Chickecn", "Sushi", "Italian"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment