Class: Array

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) is_numeric_2d_array?

Returns true if all elements are numeric in form [X,Y]



8
9
10
11
12
13
14
# File 'lib/core_ext.rb', line 8

def is_numeric_2d_array?
  self.all? do |data|
    data.is_a?(Array) &&
    data.size == 2 &&
    data.is_numeric_array?
  end
end

- (Boolean) is_numeric_array?

Returns true if all elements are numeric



3
4
5
# File 'lib/core_ext.rb', line 3

def is_numeric_array?
  self.all? {|data| data.is_a?(Numeric) }
end

- (Object) x_values

Returns all the X values of an array containing elements of the form [X,Y]

Raises:

  • (ArgumentError)


17
18
19
20
# File 'lib/core_ext.rb', line 17

def x_values
  raise ArgumentError.new("#{self.inspect} is not a 2D numeric array") unless is_numeric_2d_array?
  self.collect { |item| item.first }
end

- (Object) y_values

Returns all the Y values of an array containing elements of the form [X,Y]

Raises:

  • (ArgumentError)


23
24
25
26
# File 'lib/core_ext.rb', line 23

def y_values
  raise ArgumentError.new("#{self.inspect} is not a 2D numeric array") unless is_numeric_2d_array?
  self.collect { |item| item.last }
end