Module: Enumerable
- Defined in:
- lib/slab/enumerable.rb
Instance Method Summary collapse
- #any_not?(&block) ⇒ Boolean
- #hmap(&block) ⇒ Object
- #hmap_pair(&block) ⇒ Object (also: #build_hash)
- #inject_with_index(initial, &block) ⇒ Object
- #map_with_index ⇒ Object (also: #collect_with_index)
Instance Method Details
#any_not?(&block) ⇒ Boolean
3 4 5 |
# File 'lib/slab/enumerable.rb', line 3 def any_not?(&block) not all?(&block) end |
#hmap(&block) ⇒ Object
7 8 9 |
# File 'lib/slab/enumerable.rb', line 7 def hmap(&block) inject({}) { |hash, obj| hash[obj] = yield(obj); hash } end |
#hmap_pair(&block) ⇒ Object Also known as: build_hash
11 12 13 |
# File 'lib/slab/enumerable.rb', line 11 def hmap_pair(&block) inject({}) { |hash, obj| k,v = yield(obj); hash[k] = v; hash } end |
#inject_with_index(initial, &block) ⇒ Object
25 26 27 28 |
# File 'lib/slab/enumerable.rb', line 25 def inject_with_index(initial, &block) index = 0 inject(initial) { |memo, obj| result = yield(memo, obj, index); index += 1; result } end |
#map_with_index ⇒ Object Also known as: collect_with_index
16 17 18 19 20 21 22 |
# File 'lib/slab/enumerable.rb', line 16 def map_with_index result = [] each_with_index do |elt, idx| result << yield(elt, idx) end result end |