Project

General

Profile

Actions

Feature #12732

closed

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

Added by tenderlovemaking (Aaron Patterson) over 7 years ago. Updated over 2 years ago.

Status:
Closed
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 1 (1 open0 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0