Module: Enumerable

Defined in:
lib/hobo_support/enumerable.rb

Defined Under Namespace

Classes: MultiSender

Instance Method Summary collapse

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_whileObject



64
65
66
67
68
# File 'lib/hobo_support/enumerable.rb', line 64

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

#restObject



32
33
34
# File 'lib/hobo_support/enumerable.rb', line 32

def rest
  self[1..-1] || []
end

#take_whileObject



73
74
75
76
77
# File 'lib/hobo_support/enumerable.rb', line 73

def take_while
  take = 0
  take += 1 while yield(self[take])
  self[0..take-1]
end

#whereObject



55
56
57
# File 'lib/hobo_support/enumerable.rb', line 55

def where
  MultiSender.new(self, :select)
end

#where_notObject



59
60
61
# File 'lib/hobo_support/enumerable.rb', line 59

def where_not
  MultiSender.new(self, :reject)
end