Convert to integer Ruby
To do this safely, use Integer(value)
:
ruby
Integer("blah blah") # => ArgumentError!
Integer("5") # => 5
To do this unsafely, use to_i
:
ruby
"5abc".to_i # => 5
See ruby - Strictly convert string to integer (or nil) - Stack Overflow See Class: Integer (Ruby 2.2.3) See module Kernel - RDoc Documentation