Module: Enumerable
- Defined in:
- lib/iron/extensions/enumerable.rb
Instance Method Summary collapse
-
#convert_to_hash(init_val = nil) ⇒ Object
Converts an enumerable into a hash, by accepting an initial value or a block to compute the value for a given key.
-
#delete_unless(&block) ⇒ Object
Inverse of delete_if, to be more Ruby-ish in cases where you want negated tests.
Instance Method Details
#convert_to_hash(init_val = nil) ⇒ Object
Converts an enumerable into a hash, by accepting an initial value or a block to compute the value for a given key.
5 6 7 8 9 10 11 |
# 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) ⇒ Object
Inverse of delete_if, to be more Ruby-ish in cases where you want negated tests.
15 16 17 |
# File 'lib/iron/extensions/enumerable.rb', line 15 def delete_unless(&block) delete_if {|*args| !block.call(*args)} end |