From: matz@... Date: 2016-11-25T07:01:23+00:00 Subject: [ruby-core:78307] [CommonRuby Feature#12732][Feedback] An option to pass to `Integer`, `Float`, to return `nil` instead of raise an exception Issue #12732 has been updated by Yukihiro Matsumoto. Status changed from Open to Feedback Assignee set to Yukihiro Matsumoto Is there any problem with the following code? ``` Integer(str) rescue default_value ``` Matz. ---------------------------------------- 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-61670 * Author: Aaron Patterson * Status: Feedback * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- 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: