Skip to content

Instantly share code, notes, and snippets.

@matoni109
Created October 24, 2020 01:09
Show Gist options
  • Save matoni109/3ee28aae2e97a0c283cfca8780f6ada2 to your computer and use it in GitHub Desktop.
Save matoni109/3ee28aae2e97a0c283cfca8780f6ada2 to your computer and use it in GitHub Desktop.
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