Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created May 15, 2011 21:31
Show Gist options
  • Save ashaw/973561 to your computer and use it in GitHub Desktop.
Save ashaw/973561 to your computer and use it in GitHub Desktop.
Kernel.const_get(
self.class.to_s.titleize + "Comparisons" + self.class.to_s.titleize).where("#{self.class.to_s.downcase}_id".to_sym => self.id
).collect {|r|
Kernel.const_get(self.class.to_s.titleize + "Comparison").find(r.send("#{self.class.to_s.downcase}_comparison_id"))
}.group_by {|r|
r.send(self.class.to_s.downcase.pluralize)[1..-1].collect {|q| q.id}
}.to_a.reduce([]) { |memo, bits| memo << {:ids => bits[0], :ct => bits[1].size }; memo }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment