Module: Enumerable
- Defined in:
- lib/hobosupport/enumerable.rb
Defined Under Namespace
Classes: MultiSender
Instance Method Summary collapse
- #* ⇒ Object
- #build_hash ⇒ Object
- #drop_while ⇒ Object
- #map_hash ⇒ Object
- #map_with_index ⇒ Object
- #rest ⇒ Object
- #search(not_found = nil) ⇒ Object
- #take_while ⇒ Object
- #where ⇒ Object
- #where_not ⇒ Object
Instance Method Details
#* ⇒ Object
54 55 56 |
# File 'lib/hobosupport/enumerable.rb', line 54 def *() MultiSender.new(self, :map) end |
#build_hash ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/hobosupport/enumerable.rb', line 17 def build_hash res = {} each do |x| pair = yield x res[pair.first] = pair.last if pair end res end |
#drop_while ⇒ Object
66 67 68 69 70 |
# File 'lib/hobosupport/enumerable.rb', line 66 def drop_while drop = 0 drop += 1 while yield(self[drop]) self[drop..-1] end |
#map_hash ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/hobosupport/enumerable.rb', line 26 def map_hash res = {} each do |x| v = yield x res[x] = v end res end |
#map_with_index ⇒ Object
11 12 13 14 15 |
# File 'lib/hobosupport/enumerable.rb', line 11 def map_with_index res = [] each_with_index {|x, i| res << yield(x, i)} res end |
#rest ⇒ Object
35 36 37 |
# File 'lib/hobosupport/enumerable.rb', line 35 def rest self[1..-1] end |
#search(not_found = nil) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/hobosupport/enumerable.rb', line 3 def search(not_found=nil) each do |x| val = yield(x) return val if val end not_found end |
#take_while ⇒ Object
73 74 75 76 77 |
# File 'lib/hobosupport/enumerable.rb', line 73 def take_while take = 0 take += 1 while yield(self[take]) self[0..take-1] end |
#where ⇒ Object
58 59 60 |
# File 'lib/hobosupport/enumerable.rb', line 58 def where MultiSender.new(self, :select) end |
#where_not ⇒ Object
62 63 64 |
# File 'lib/hobosupport/enumerable.rb', line 62 def where_not MultiSender.new(self, :reject) end |