4 ms·
I think you're looking in the wrong place, `BasicObject` has no `respond_to?` so you'd need to trace the `rand_random` execution to see what ends up calling `re
by tvon 10y ago
I think you're looking in the wrong place, `BasicObject` has no `respond_to?` so you'd need to trace the `rand_random` execution to see what ends up calling `respond_to?` on your `BasicObject` instance. Poking through github I'm guessing it's `rb_funcallv_public` but I may be missing something(s).
- tcopeland 10y agoBut that's just it; I would have thought the NoMethodError would have been around the missing "respond_to?" - like it was in 2.2.3 - not around a missing "begin".
- mnarayan01 10y agoLike @tvon, I'm not up to digging through the code, but I'd guess it's falling through to eventually make an unconditional call to http://ruby-doc.org/core-2.3.0/Range.html#method-i-begin http://ruby-doc.org/core-2.3.0/Range.html#method-i-begin.
- tcopeland 10y agoThat's exactly right; but that's happening because vm_respond_to is returning true on a nil method entry. It's a puzzler...
- mnarayan01 10y agoI assume you mean at https://github.com/ruby/ruby/blob/v2_3_0/vm_method.c#L1915-L1919 https://github.com/ruby/ruby/blob/v2_3_0/vm_method.c#L1915-L.... Agreed it's weird that rb_respond_to will now return true for objects where respond_to is undefined. Though I guess I can see upsides to doing so, and it would require something pretty weird to result in "wrong" behavior.
- tcopeland 10y agoYup that's the code that I'm wondering about. The case I ran into was in a Rails 4.1 app where ActiveSupport::Duration (which subclassed BasicObject) was used like this: "rand(10.minutes)". That raised an exception in 2.3.0 but worked fine in 2.2.3. The fix was simple - "rand(10.minutes.to_i)". But still, I don't understand it.
- mnarayan01 10y agoHeh...I also ran into an issue with ActiveSupport::Duration, though in my case when passed as the only argument to a method with a signature along the lines of `f(time = 30, [star][star]options)`, with the error involving #to_hash. Since newer versions of ActiveSupport fix it, I didn't look into it too careful (just called #to_i). I'm glad you did!
- tcopeland 10y agoYeah sounds like in the same ballpark. David Stostik did a nice writeup of the oddities of ActiveSupport::Duration 4.1 here http://www.bnjs.co/2015/01/14/rails-date-class-durations-and-ruby-basicobject/ http://www.bnjs.co/2015/01/14/rails-date-class-durations-and.... I'm surprised that I haven't seen anything about that respond_to? change in the blogs; maybe I've just missed it. I might blog this, although I hate ending a post with "gosh I don't know about this one". Makes me feel like I haven't done all my homework.
- tcopeland 10y agoAh ha! It was a Ruby bug... longer writeup here: http://thomasleecopeland.com/2016/06/26/basicobject-is-a-range.html http://thomasleecopeland.com/2016/06/26/basicobject-is-a-ran...