[ruby-core:109848] [Ruby master Bug#18998] Kernel#Integer does not convert SimpleDelegator expectly
From:
"taichi730 (Taichi Ishitani)" <noreply@...>
Date:
2022-09-08 13:21:32 UTC
List:
ruby-core #109848
Issue #18998 has been reported by taichi730 (Taichi Ishitani).
----------------------------------------
Bug #18998: Kernel#Integer does not convert SimpleDelegator expectly
https://bugs.ruby-lang.org/issues/18998
* Author: taichi730 (Taichi Ishitani)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Kernel#Integer method doens not convert a SimpleDelegator object of which value is a String.
This is an sample code.
``` ruby
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?
--
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>