Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/admin-utils/string.rb

Instance Method Summary collapse

Instance Method Details

#is_number?Boolean

Custom String method to check if a string can be parsed to a number (Integer)

This method is called directly on a String object

Returns:

  • true String can be parsed to an Integer

  • false String can not be parsed to an Integer

Example:

require 'admin-utils/string'
.
.
.
puts "is a number" if "12345".is_number?

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/admin-utils/string.rb', line 19

def is_number?
  Integer(self)
  true
rescue
  false
end