class AvaRbToolbox::Enumerable
This class extends functionality of an enumerable @author Anton Kuzmin
Public Class Methods
new(target)
click to toggle source
# File lib/ava_rb_toolbox/enumerable.rb, line 13 def initialize(target) @target = target end
Public Instance Methods
group_by_unique(proc = nil, &block)
click to toggle source
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.
@return [Hash]
# 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