Bug #16297 closed
calling undefined allocator by `Class.instance_method(:allocate)`
Added by nobu (Nobuyoshi Nakada) over 5 years ago.
Updated about 1 year ago.
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.
Backport changed from 2.5: REQUIRED, 2.6: REQUIRED to 2.5: REQUIRED, 2.6: DONE
ruby_2_6 r67896 merged revision(s) f72dc407.
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
.
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 )
Also available in: Atom
PDF
Like 0
Like 0 Like 0 Like 0