Class: Array
- 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
- #delete_at_many(*indices) ⇒ Object
- #delete_many(*elements) ⇒ Object
-
#extract_options! ⇒ Object
Extracts options from a set of arguments.
- #partial_sums(initial = 0.0) ⇒ Object
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 (*args)
args.
end
(1, 2) # => {}
(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 if last.is_a?(Hash) && last. 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 |