Created
January 25, 2018 10:36
-
-
Save Spone/a1093dd8198dff6b4dc1a43d81b26816 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| @restaurant = restaurant | |
| end | |
| end |
This file contains hidden or 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, location, food, seats, serving_time) | |
| # STATE : instance variables | |
| super(name, location, food, seats) | |
| @serving_time = serving_time | |
| end | |
| def book!(customer_name) | |
| puts "Sorry #{customer_name} we don't accept bookings." | |
| end | |
| end |
This file contains hidden or 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 "chef" | |
| class GastroRestaurant < Restaurant | |
| attr_reader :chef | |
| def initialize(name, location, food, seats, chef_name = nil) | |
| # STATE : instance variables | |
| # super runs the `initialize` method from the | |
| # Restaurant class | |
| super(name, location, food, seats) | |
| unless chef_name.nil? | |
| @chef = Chef.new(chef_name, self) | |
| end | |
| end | |
| def open? | |
| # super runs the instance method `open?` from the | |
| # Restaurant class | |
| super || | |
| Time.now.hour >= 11 && Time.now.hour <= 14 | |
| end | |
| end |
This file contains hidden or 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 Restaurant | |
| attr_reader :name, :location, :food | |
| def initialize(name, location, food, seats) | |
| # STATE : instance variables | |
| @name = name | |
| @location = location | |
| @food = food | |
| @seats = seats | |
| @customers = [] | |
| end | |
| # class method | |
| def self.categories | |
| ["burgers", "thai", "french"] | |
| end | |
| # below are instance methods | |
| def open? | |
| Time.now.hour >= 18 && Time.now.hour <= 22 | |
| end | |
| def closed? | |
| !open? | |
| end | |
| def book!(customer_name) # instance method | |
| @customers << customer_name | |
| end | |
| def customers_count | |
| @customers.size | |
| end | |
| end |
This file contains hidden or 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 "fastfood_restaurant" | |
| require_relative "gastro_restaurant" | |
| the_butcher = Restaurant.new( | |
| "The Butcher", "Amsterdam", "burgers", 50) | |
| # puts "This restaurant is called #{the_butcher.name}" | |
| # puts "It's located in #{the_butcher.location}" | |
| # puts "They have #{the_butcher.customers_count} customers." | |
| # the_butcher.book!("Feiko") | |
| # puts "They have #{the_butcher.customers_count} customers." | |
| # burger_king = FastfoodRestaurant.new( | |
| # "Burger King", "Amsterdam", "burgers", 80, 5) | |
| # p burger_king | |
| # burger_king.book!("Hans") | |
| # p burger_king | |
| bordeau = GastroRestaurant.new( | |
| "Bord'eau", "Amsterdam", "dutch", 40, | |
| "Richard van Ostenbrugge") | |
| p bordeau | |
| puts "The chef is #{bordeau.chef.name}" | |
| my_restaurant = GastroRestaurant.new( | |
| "My restaurant", "Amsterdam", "spanish", 20, | |
| "me") | |
| p my_restaurant | |
| puts "The chef is #{my_restaurant.chef.name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment