Created
April 7, 2020 00:42
-
-
Save rpdecks/26ce5dda83e6c6010df95b53fe31abe6 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 Ingredient | |
@@all = [] | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
@@all << self | |
end | |
def self.all | |
@@all | |
end | |
def users | |
## isn't this missing the select? I think you're trying to do Allergy.all.select then map? | |
allergens = Allergy.all do |allergy| | |
allergy.ingredient == self | |
end | |
allergens.map { |allergy| allergy.user }.uniq | |
end | |
def self.most_common_allergen | |
all.max_by do |ingredient| | |
ingredient.users.count | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment