Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/BioDSL/csv.rb

Overview

Monkey patching Array to add convert_types method.

Instance Method Summary collapse

Instance Method Details

#convert_types(types) ⇒ Object

Method that converts variable types given an array of types. Example: [“fish”, 0.0, 1].convert_types([:to_s, :to_f, :to_i])



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/BioDSL/csv.rb', line 32

def convert_types(types)
  if size != types.size
    fail ArgumentError, "Array and types size mismatch: #{size} != " \
      "#{types.size}"
  end

  types.each_with_index do |type, i|
    self[i] = self[i].send(type)
  end

  self
end