From: tenderlove@... Date: 2018-02-07T19:17:50+00:00 Subject: [ruby-core:85465] [CommonRuby Feature#12732] An option to pass to `Integer`, `Float`, to return `nil` instead of raise an exception Issue #12732 has been updated by tenderlovemaking (Aaron Patterson). Something like `Integer(x, rescue: default_value)` is fine for me too, (or `Integer(x, ->() { default_value })`, which is similar to `[].find(->() { missing_value }) { ... }`) Configuring with a default value seems more flexible. ---------------------------------------- Feature #12732: An option to pass to `Integer`, `Float`, to return `nil` instead of raise an exception https://bugs.ruby-lang.org/issues/12732#change-70256 * Author: tenderlovemaking (Aaron Patterson) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- 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) -- https://bugs.ruby-lang.org/ Unsubscribe: