From 9b9fe826fd1ce825af3503f39643f75910307a51 Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 22 Dec 2018 22:39:31 +0000 Subject: {complex,object,rational}.c: document exception: false From: Victor Shepelev [ruby-core:90673] [Bug #15452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 637a301791..4778118391 100644 --- a/object.c +++ b/object.c @@ -3221,7 +3221,7 @@ opts_exception_p(VALUE opts) /* * call-seq: - * Integer(arg, base=0) -> integer + * Integer(arg, base=0, exception: true) -> integer * * Converts arg to an Integer. * Numeric types are converted directly (with floating point numbers @@ -3232,15 +3232,23 @@ opts_exception_p(VALUE opts) * In any case, strings should be strictly conformed to numeric * representation. This behavior is different from that of * String#to_i. Non string values will be converted by first - * trying to_int, then to_i. Passing nil - * raises a TypeError. + * trying to_int, then to_i. + * + * Passing nil raises a TypeError, while passing String that + * does not conform with numeric representation raises an ArgumentError. + * This behavior can be altered by passing exception: false, + * in this case not convertible value will return nil. * * Integer(123.999) #=> 123 * Integer("0x1a") #=> 26 * Integer(Time.new) #=> 1204973019 * Integer("0930", 10) #=> 930 * Integer("111", 2) #=> 7 - * Integer(nil) #=> TypeError + * Integer(nil) #=> TypeError: can't convert nil into Integer + * Integer("x") #=> ArgumentError: invalid value for Integer(): "x" + * + * Integer("x", exception: false) #=> nil + * */ static VALUE @@ -3575,17 +3583,19 @@ rb_Float(VALUE val) /* * call-seq: - * Float(arg) -> float + * Float(arg, exception: true) -> float * * Returns arg converted to a float. Numeric types are converted * directly, and with exception to string and nil the rest are converted using arg.to_f. * Converting a string with invalid characters will result in a ArgumentError. * Converting nil generates a TypeError. + * Exceptions could be suppressed by passing exception: false. * * Float(1) #=> 1.0 * Float("123.456") #=> 123.456 * Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring" * Float(nil) #=> TypeError: can't convert nil into Float + * Float("123.0_badstring", exception: false) #=> nil */ static VALUE -- cgit v1.2.3