Class: Array

Inherits:
Object show all
Defined in:
lib/bioinform/support/array_zip.rb,
lib/bioinform/support/delete_many.rb,
lib/bioinform/support/partial_sums.rb,
lib/bioinform/support/array_product.rb,
lib/bioinform/support/third_part/active_support/core_ext/array/extract_options.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.product(*arrays) ⇒ Object



2
3
4
5
# File 'lib/bioinform/support/array_product.rb', line 2

def self.product(*arrays)
  return []  if arrays.empty?
  arrays.first.product(*arrays[1..-1])
end

.zip(*arrays) ⇒ Object



2
3
4
5
# File 'lib/bioinform/support/array_zip.rb', line 2

def self.zip(*arrays)
  return []  if arrays.empty?
  arrays.first.zip(*arrays[1..-1])
end

Instance Method Details

#delete_at_many(*indices) ⇒ Object



2
3
4
# File 'lib/bioinform/support/delete_many.rb', line 2

def delete_at_many(*indices)
  indices.uniq.sort.reverse.each{|ind| delete_at ind}
end

#delete_many(*elements) ⇒ Object



5
6
7
# File 'lib/bioinform/support/delete_many.rb', line 5

def delete_many(*elements)
  elements.each{|el| delete el}
end

#extract_options!Object

Extracts options from a set of arguments. Removes and returns the last element in the array if it’s a hash, otherwise returns a blank hash.

def options(*args)
  args.extract_options!
end

options(1, 2)           # => {}
options(1, 2, :a => :b) # => {:a=>:b}


22
23
24
25
26
27
28
# File 'lib/bioinform/support/third_part/active_support/core_ext/array/extract_options.rb', line 22

def extract_options!
  if last.is_a?(Hash) && last.extractable_options?
    pop
  else
    {}
  end
end

#partial_sums(initial = 0.0) ⇒ Object



4
5
6
7
# File 'lib/bioinform/support/partial_sums.rb', line 4

def partial_sums(initial = 0.0)
  sums = initial
  map{|el| sums += el}
end