Project

General

Profile

Feature #12732

An option to pass to `Integer`, `Float`, to return `nil` instead of raise an exception

Added by tenderlovemaking (Aaron Patterson) almost 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:77171]

Description

I would like to be able to pass an option to Integer() and Float() so that they don't raise an exception, but return nil instead. For example:

Integer(string, exception: false)

The reason I want this function is so that I can convert strings from YAML or JSON to integers if they parse correctly, or just return strings if they can't be parsed.


Files

integer-parse.pdf (29 KB) integer-parse.pdf tenderlovemaking (Aaron Patterson), 09/07/2016 06:55 AM

Related issues

Related to Ruby master - Feature #12968: Allow default value via block for Integer(), Float() and Rational()OpenActions

Also available in: Atom PDF