module Enumerable
Public Instance Methods
convert_to_hash(init_val = nil) { |key| ... }
click to toggle source
Converts an enumerable into a hash, by accepting an initial value or a block to compute the value for a given key.
# File lib/iron/extensions/enumerable.rb, line 5 def convert_to_hash(init_val = nil) hash = {} self.each do |key| hash[key] = block_given? ? yield(key) : (init_val.dup rescue init_val) end hash end
delete_unless(&block)
click to toggle source
Inverse of delete_if, to be more Ruby-ish in cases where you want negated tests.
# File lib/iron/extensions/enumerable.rb, line 15 def delete_unless(&block) delete_if {|*args| !block.call(*args)} end