Class: Array

Inherits:
Object show all
Defined in:
lib/quickbooks/ruby_ext.rb

Instance Method Summary collapse

Instance Method Details

#check_all?Boolean

Returns:



27
28
29
30
31
# File 'lib/quickbooks/ruby_ext.rb', line 27

def check_all?
  passed = true
  each { |e| passed = false unless yield(e) }
  passed
end

#group_by_count(int) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/quickbooks/ruby_ext.rb', line 12

def group_by_count(int)
  ary = []
  nxt = 0
  until(nxt*4 > length)
    n = []
    int.times do |i|
      break if nxt*4+i >= length
      n << self[nxt*4+i]
    end
    nxt += 1
    ary << n unless n.empty?
  end
  ary
end

#occurrances_ofObject



33
34
35
36
37
# File 'lib/quickbooks/ruby_ext.rb', line 33

def occurrances_of
  count = 0
  each { |e| count += 1 if yield(e) }
  count
end

#to_hash_via(&block) ⇒ Object

Expects the block to receive each element and return a two-element array



8
9
10
# File 'lib/quickbooks/ruby_ext.rb', line 8

def to_hash_via(&block) # Expects the block to receive each element and return a two-element array
  Hash[*(collect {|e| yield e}.flatten)]
end