Class: AvaRbToolbox::Enumerable
- Inherits:
-
Object
- Object
- AvaRbToolbox::Enumerable
- Defined in:
- lib/ava_rb_toolbox/enumerable.rb
Overview
This class extends functionality of an enumerable
Instance Method Summary collapse
-
#group_by_unique(proc = nil, &block) ⇒ Hash
Groups enumerable entries by key returned by ‘proc` or `block` into hash where value is an enumerable’s entry.
-
#initialize(target) ⇒ Enumerable
constructor
A new instance of Enumerable.
Constructor Details
#initialize(target) ⇒ Enumerable
Returns a new instance of Enumerable.
13 14 15 |
# File 'lib/ava_rb_toolbox/enumerable.rb', line 13 def initialize(target) @target = target end |
Instance Method Details
#group_by_unique(proc = nil, &block) ⇒ Hash
Groups enumerable entries by key returned by ‘proc` or `block` into hash where value is an enumerable’s entry.
If ‘block` is given, `proc` is ignored.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ava_rb_toolbox/enumerable.rb', line 23 def group_by_unique(proc = nil, &block) result = {} return result if proc.nil? and !block_given? proc = block if block_given? @target.each_entry do |item| result[proc.call(item)] = item end result end |