You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[3.1.2] > class B; def to_str; 'B'; end; end
=> :to_str
[3.1.2] > Time.at(12, in: B.new)
=> 1970-01-01 02:00:12 +0200
[3.1.2] > class C; def to_str; raise 'crash'; end; end
=> :to_str
[3.1.2] > Time.at(12, in: C.new)
(irb):10:in `to_str': crash (RuntimeError)
from <internal:timev>:274:in `at'
from (irb):11:in `<main>'
from /usr/local/var/rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
from /usr/local/var/rbenv/versions/3.1.2/bin/irb:25:in `load'
from /usr/local/var/rbenv/versions/3.1.2/bin/irb:25:in `<main>'
[3.1.2] > class D; def to_int; raise 'dint'; end; def to_str; raise 'dstr'; end; end
=> :to_str
[3.1.2] > Time.at(12, in: D.new)
(irb):12:in `to_str': dstr (RuntimeError)
from <internal:timev>:274:in `at'
from (irb):13:in `<main>'
from /usr/local/var/rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
from /usr/local/var/rbenv/versions/3.1.2/bin/irb:25:in `load'
from /usr/local/var/rbenv/versions/3.1.2/bin/irb:25:in `<main>'
It looks like MRI prefers to implicitly convert through #to_str if it exists and otherwise will convert through #to_int. We can check for this by doing a Value::respond_to check.
This doesn't look quite right.
It looks like MRI prefers to implicitly convert through
#to_str
if it exists and otherwise will convert through#to_int
. We can check for this by doing aValue::respond_to
check.Originally posted by @lopopolo in #1956 (comment)
The text was updated successfully, but these errors were encountered: