Actions
Bug #16297
closedcalling undefined allocator by `Class.instance_method(:allocate)`
Description
For instance, Rational.allocate
is undefined.
Rational.allocate #=> undefined method `allocate' for Rational:Class (NoMethodError)
But it can be called by Class.instance_method(:allocate)
.
Class.instance_method(:allocate).bind_call(Rational) #=> (0/1)
Class.instance_method(:allocate).bind(Rational).call #=> (0/1)
These allocators are defined for Marshal, and undefined as methods.
Updated by usa (Usaku NAKAMURA) almost 4 years ago
- Backport changed from 2.5: REQUIRED, 2.6: REQUIRED to 2.5: REQUIRED, 2.6: DONE
ruby_2_6 r67896 merged revision(s) f72dc407.
Updated by usa (Usaku NAKAMURA) almost 4 years ago
usa (Usaku NAKAMURA) wrote in #note-1:
ruby_2_6 r67896 merged revision(s) f72dc407.
note that ruby_2_6 does not have UnboundMethod#bind_call
.
Updated by jhawthorn (John Hawthorn) 9 months ago
I'm not sure if there's a deeper problem this causes, but it is still possible after this patch to call the allocator on a Rational through defining an arbitrary allocate
method.
>> def Rational.allocate; end
=> :allocate
>> Class.instance_method(:allocate).bind_call(Rational)
=> (0/1)
Actions
Like0
Like0Like0Like0