[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115523] [Ruby master Feature#19931] to_int is not for implicit conversion?
From:
"Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@...>
Date:
2023-11-28 20:11:36 UTC
List:
ruby-core #115523
Issue #19931 has been updated by Dan0042 (Daniel DeLorme).
A few weeks ago I experimented and tried to polyfill this via Object#coerce, and it doesn't result in `0 ^ 1.1 == 1`
```ruby
class Object
def coerce(other)
if self.respond_to?(:to_int)
to_int.coerce(other)
else
raise TypeError, "#{self.class} can't be coerced into #{other.class}"
end
end
end
x = Object.new
def x.to_int = 5
1 + x #=> 6
0 ^ 1.1 #1.1 can't be coerced into Integer (TypeError)
```
----------------------------------------
Feature #19931: to_int is not for implicit conversion?
https://bugs.ruby-lang.org/issues/19931#change-105454
* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
While reviewing some implicit vs explicit conversion concepts, I discovered that arithmetic operations do not perform the implicit conversion I expected from #to_int
```ruby
o = Object.new
def o.to_int; 1; end
1 + o #TypeError
```
I understand there's the whole #coerce thing for numbers, but I had expected #to_int to fit neatly into this and cause the object to be implicitly coerced to Integer.
So basically I thought that #to_i was for explicit conversion and #to_int for implicit conversion; is that not the case?
Most of the internet seems to think that (to_int : to_i) relationship is like (to_str : to_s). But I can't seems to find authoritative documentation on the topic.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/