Module: Enumerable
- Defined in:
- lib/hobo_support/enumerable.rb
Defined Under Namespace
Classes: MultiSender
Instance Method Summary collapse
- #* ⇒ Object
- #build_hash(res = {}) ⇒ Object
- #drop_while ⇒ Object
- #map_and_find(not_found = nil) ⇒ Object
- #map_hash(res = {}) ⇒ Object
- #map_with_index(res = []) ⇒ Object
- #rest ⇒ Object
- #take_while ⇒ Object
- #where ⇒ Object
- #where_not ⇒ Object
Instance Method Details
#* ⇒ Object
51 52 53 |
# File 'lib/hobo_support/enumerable.rb', line 51 def *() MultiSender.new(self, :map) end |
#build_hash(res = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/hobo_support/enumerable.rb', line 16 def build_hash(res={}) each do |x| pair = block_given? ? yield(x) : x res[pair.first] = pair.last if pair end res end |
#drop_while ⇒ Object
63 64 65 66 67 |
# File 'lib/hobo_support/enumerable.rb', line 63 def drop_while drop = 0 drop += 1 while yield(self[drop]) self[drop..-1] end |
#map_and_find(not_found = nil) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/hobo_support/enumerable.rb', line 3 def map_and_find(not_found=nil) each do |x| val = yield(x) return val if val end not_found end |
#map_hash(res = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/hobo_support/enumerable.rb', line 24 def map_hash(res={}) each do |x| v = yield x res[x] = v end res end |
#map_with_index(res = []) ⇒ Object
11 12 13 14 |
# File 'lib/hobo_support/enumerable.rb', line 11 def map_with_index(res=[]) each_with_index {|x, i| res << yield(x, i)} res end |
#rest ⇒ Object
32 33 34 |
# File 'lib/hobo_support/enumerable.rb', line 32 def rest self[1..-1] || [] end |
#take_while ⇒ Object
70 71 72 73 74 |
# File 'lib/hobo_support/enumerable.rb', line 70 def take_while take = 0 take += 1 while yield(self[take]) self[0..take-1] end |
#where ⇒ Object
55 56 57 |
# File 'lib/hobo_support/enumerable.rb', line 55 def where MultiSender.new(self, :select) end |
#where_not ⇒ Object
59 60 61 |
# File 'lib/hobo_support/enumerable.rb', line 59 def where_not MultiSender.new(self, :reject) end |