Class: Array

Inherits:
Object show all
Defined in:
lib/utilities/array.rb

Instance Method Summary collapse

Instance Method Details

#map_with(*args, &block) ⇒ Object

Zip *args then call &block



29
30
31
# File 'lib/utilities/array.rb', line 29

def map_with( *args, &block )
  zip(*args).map{|i| yield i }
end

#numerics?(allow_nil = false) ⇒ Boolean Also known as: numeric?, narray?

Returns true if the array contains only numerical values

Returns:

  • (Boolean)


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

def numerics?( allow_nil = false )
  (allow_nil ? compact : self).reject{ |x| x.is_a?( Numeric ) }.empty?
end

#reverse_sortObject Also known as: rsort

Returns a copy of self reverse sorted



17
18
19
# File 'lib/utilities/array.rb', line 17

def reverse_sort
  dup.rsort!
end

#reverse_sort!Object Also known as: rsort!

Reverse sort self



23
24
25
# File 'lib/utilities/array.rb', line 23

def reverse_sort!
  sort!{|x,y| y <=> x }
end

#to_numerics(allow_nil = false) ⇒ Object Also known as: to_numeric, to_narray

Transforms an array to an array of float values



10
11
12
# File 'lib/utilities/array.rb', line 10

def to_numerics( allow_nil = false )
  map{ |x| allow_nil && x.nil? ? nil : x.to_f }
end

#to_statObject Also known as: to_stats

Returns a copy of self that includes the Statistics methods



34
35
36
# File 'lib/utilities/array.rb', line 34

def to_stat
  dup.to_stat!
end

#to_stat!Object Also known as: to_stats!

Adds the statistics methods to self



40
41
42
# File 'lib/utilities/array.rb', line 40

def to_stat!
  extend(Utilities::Statistics)
end

#wrap(left_and_right, right = nil) ⇒ Object



45
46
47
48
49
# File 'lib/utilities/array.rb', line 45

def wrap left_and_right, right = nil
  left_and_right = left_and_right.to_s
  right = right.nil? ? left_and_right : right.to_s
  map {|item| [left_and_right.to_s, item.to_s, right.to_s].join}
end