Project

General

Profile

Actions

Bug #3684

closed

String#to_i documentation mismatch

Added by sakuro (Sakuro OZAWA) over 14 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
Backport:
[ruby-core:31685]

Description

=begin
Missing:

Giving base 0 makes this method take prefix into account.
ex. "0xFF".to_i(0) #=> 255

Wrong:

string.c rb_str_to_i says:

This method never raises an exception.

But it raises

  • ArgumentError when the given base is out of range
  • TypeError when converting the base into Integer is failed

% ruby -ve '"123".to_i(99)'
ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-linux]
-e:1:in to_i': invalid radix 99 (ArgumentError) from -e:1:in '

% ruby -ve '"123".to_i(nil)'
ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-linux]
-e:1:in to_i': no implicit conversion from nil to integer (TypeError) from -e:1:in '

% ruby -ve '"123".to_i(false)'
ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-linux]
-e:1:in to_i': can't convert false into Integer (TypeError) from -e:1:in '
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0