Created
October 24, 2020 01:09
-
-
Save matoni109/3ee28aae2e97a0c283cfca8780f6ada2 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 Restaurant | |
# TODO: add relevant accessors if necessary | |
attr_reader :average_rating, :city | |
attr_writer :ratings # :restaurants | |
def self.filter_by_city(restaurants, city) | |
restaurants.select{|rest| rest.city == city } | |
end | |
def initialize(city, name) | |
# TODO: implement constructor with relevant instance variables | |
@city = city | |
@name = name | |
@average_rating = 0.0 | |
@ratings = [] | |
@restaurants = [] | |
end | |
def rate(new_rate) | |
@ratings << new_rate | |
@average_rating = (@ratings.sum) / @ratings.length | |
end | |
# TODO: implement .filter_by_city and #rate methods | |
end | |
# jules_verne = Restaurant.new("paris", "Jules Verne") | |
# bluebird = Restaurant.new("london", "Bluebird") | |
# daniel = Restaurant.new("new york", "Daniel") | |
# restaurants = [jules_verne, bluebird, daniel] | |
# # p Restaurant.filter_by_city(restaurants, "london") | |
# p daniel.city |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment