Collect for a hash
module Enumerable
def hash_map
hash = {}
self.each {|o| hash.store(*yield(o))}
hash
end
end
my_hash = lines.hash_map {|l| l.split /:/}
Great suggestion on redit for creating a hash from other objects.
module Enumerable
def hash_map
hash = {}
self.each {|o| hash.store(*yield(o))}
hash
end
end
my_hash = lines.hash_map {|l| l.split /:/}
Great suggestion on redit for creating a hash from other objects.