Project

General

Profile

Actions

Bug #3684

closed

String#to_i documentation mismatch

Added by sakuro (Sakuro OZAWA) about 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 #1

Updated by naruse (Yui NARUSE) about 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r29332.
Sakuro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions #2

Updated by naruse (Yui NARUSE) over 11 years ago

  • Tracker changed from Misc to Bug
Actions

Also available in: Atom PDF

Like0
Like0Like0