Class: Enumark::Grouping
- Inherits:
-
Object
- Object
- Enumark::Grouping
- Defined in:
- lib/enumark/grouping.rb
Defined Under Namespace
Classes: Group
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(enumark, key, &post) ⇒ Grouping
constructor
A new instance of Grouping.
Constructor Details
#initialize(enumark, key, &post) ⇒ Grouping
Returns a new instance of Grouping.
8 9 10 11 12 13 14 15 |
# File 'lib/enumark/grouping.rb', line 8 def initialize(enumark, key, &post) @lock = Mutex.new @collection = nil @enumark = enumark @key = key @post = post end |
Instance Method Details
#each(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/enumark/grouping.rb', line 17 def each(&block) unless @collection @lock.synchronize do @collection = @enumark.group_by(&@key) @collection = @post.call(@collection) if @post @collection = @collection.map{ |k, items| Group.new(k, items) } end end @collection.each(&block) end |