[Nitro] 0.26.0 preview

George Moschovitis george.moschovitis at gmail.com
Thu Dec 15 10:25:18 EST 2005


> perhaps Trans can add a facets enumerator helper like this:


Well it is so easy so here you go:

require 'mega/functor'

module Enumerable

  # Project has_many Group
  # Group has_many User
  # projects.groups.accumulate.users
  #--
  # gmosx: any idea for a better name?
  #++

  def accumulate
    Functor.new do |op, *args|
      self.inject([]) { |a, x| a << x.send(op, *args) }.flatten
    end
  end
  alias_method :acc, :accumulate

end


project.groups.accumulate.users


-g.

--
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com




More information about the Nitro-general mailing list