Issue #12732 has been updated by knu (Akinori MUSHA).


Just for the record, `Integer(x, rescue: default_value)` might be an idea, if anything other than `nil` (like zero) would be desired.

----------------------------------------
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-69743

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>