Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/utilities.rb
Instance Method Summary collapse
-
#numerics?(allow_nil = false) ⇒ Boolean
(also: #numeric?, #narray?)
Returns true if the array contains only numerical values.
-
#reverse_sort ⇒ Object
(also: #rsort)
Returns a copy of self reverse sorted.
-
#reverse_sort! ⇒ Object
(also: #rsort!)
Reverse sort self.
-
#to_numerics ⇒ Object
(also: #to_numeric, #to_narray)
Transforms an array.
-
#to_stat ⇒ Object
(also: #to_stats)
Returns a copy of self that includes the Statistics methods.
-
#to_stat! ⇒ Object
(also: #to_stats!)
Adds the statistics methods to self.
Instance Method Details
#numerics?(allow_nil = false) ⇒ Boolean Also known as: numeric?, narray?
Returns true if the array contains only numerical values
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_sort ⇒ Object 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_numerics ⇒ Object 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_stat ⇒ Object 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 |