Project

General

Profile

Actions

Bug #18998

closed

Kernel#Integer does not convert SimpleDelegator object expectly

Added by taichi730 (Taichi Ishitani) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
[ruby-core:109848]

Description

Kernel#Integer method doens not convert a SimpleDelegator object of which value is a String.
This is an sample code.

require 'delegate'
p Integer(SimpleDelegator.new('0x10'))

I expect Kernel#Integer to convert the input value as a String and the expected returned value is 16.
Hoever the actual returned value is 0 so it's seemed that #to_i method is just called.

taichi@LAPTOP-TVTKLNFD:temp
$ cat test.rb
require 'delegate'
p Integer(SimpleDelegator.new('0x10'))

taichi@LAPTOP-TVTKLNFD:temp
$ ruby test.rb
0

Which is the correct behavior?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0