Skip to content

Instantly share code, notes, and snippets.

@MostlyFocusedMike
Last active May 5, 2018 23:37
Show Gist options
  • Save MostlyFocusedMike/42a53de3e85923b27424b0cd55827425 to your computer and use it in GitHub Desktop.
Save MostlyFocusedMike/42a53de3e85923b27424b0cd55827425 to your computer and use it in GitHub Desktop.
class BelongsToClass
# accessors and whatnot
@@all = []
def initialize(has_many_class_a_obj, has_many_class_b_obj)
@has_many_class_a_obj = has_many_class_a_obj
@has_many_class_b_obj = has_many_class_b_obj
end
def self.all
@@all
end
end
class HasManyClassA
# ...initializations and whatnot
def all_belongs_to_objects
BelongsToClass.all.select do |belongs_to_obj|
belongs_to_obj.has_many_a_obj == self
end
end
def all_has_many_class_b_objects
self.all_belongs_to_objects.map do |belongs_to_obj|
belongs_to_obj.has_many_b_obj
end
end
end
class HasManyClassB
# reverse the _a_'s for _b_'s from above to get this class
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment