lib/abstractivator/enumerable_ext.rb in abstractivator-0.0.21 vs lib/abstractivator/enumerable_ext.rb in abstractivator-0.0.22
- old
+ new
@@ -1,6 +1,7 @@
require 'set'
+require 'abstractivator/proc_ext'
module Enumerable
# joins items from left with items from right based on their keys.
# get_{left,right}_key are callables which, given an item, return the item's key.
@@ -46,10 +47,10 @@
def self.proc?(x)
x.respond_to?(:call)
end
def hash_map(get_key=->x{x}, &get_value)
- Hash[self.map{|x| [get_key.(x), get_value ? get_value.(x) : x]}]
+ Hash[self.map{|x| [Proc.loose_call(get_key, [x]), get_value ? get_value.call(x) : x]}]
end
def outer_join(right, get_left_key, get_right_key, default_value)
Enumerable.outer_join(self, right, get_left_key, get_right_key, default_value, default_value)
end