Class: Array

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

Overview

Numeric Additions.

Instance Method Summary collapse

Instance Method Details

#to_numNumeric?

Tries to convert the joined result of this Array into a number. If this fails, nil is returned.

Examples:

[1,2,3,4].to_num            # => 1234
[1, '1.5', 6, 7].to_num     # => 11.567
[1, 'a', 2].to_num          # => nil

Returns:

  • (Numeric, nil)

    depending on whether joining returns a valid number String.



71
72
73
# File 'lib/a_types/core_ext/numeric.rb', line 71

def to_num
  join.to_num
end