Class: Array

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

Instance Method Summary collapse

Instance Method Details

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

Returns true if the array contains only numerical values

Returns:

  • (Boolean)


266
267
268
# File 'lib/utilities.rb', line 266

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



280
281
282
# File 'lib/utilities.rb', line 280

def reverse_sort
  dup.rsort!
end

#reverse_sort!Object Also known as: rsort!

Reverse sort self



286
287
288
# File 'lib/utilities.rb', line 286

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

#to_numericsObject Also known as: to_numeric, to_narray

Transforms an array



273
274
275
# File 'lib/utilities.rb', line 273

def to_numerics
  map{ |x| x.to_f }
end

#to_statObject Also known as: to_stats

Returns a copy of self that includes the Statistics methods



292
293
294
# File 'lib/utilities.rb', line 292

def to_stat
  dup.to_stat!
end

#to_stat!Object Also known as: to_stats!

Adds the statistics methods to self



298
299
300
# File 'lib/utilities.rb', line 298

def to_stat!
  extend(Utilities::Statistics)
end