Bug #15572
closed`RubyVM::InstructionSequence` doesn't work with `extend`.
Description
For some reason,RubyVM::InstructionSequence.extend
doesn't seem to work as expected.
module Loader
def load_iseq(path)
puts path
return compile_file(path)
end
end
# This doesn't work?
# RubyVM::InstructionSequence.extend(Loader)
# This works:
class << RubyVM::InstructionSequence
prepend Loader
end
Updated by wanabe (_ wanabe) about 5 years ago
ioquatix (Samuel Williams) wrote:
For some reason,
RubyVM::InstructionSequence.extend
doesn't seem to work as expected.
Kernel#extend
seems to work fine.
$ ./miniruby -ve 'module Foo; def foo; p :foo; end; end; RubyVM::InstructionSequence.extend(Foo); RubyVM::InstructionSequence.foo'
ruby 2.7.0dev (2019-01-30 trunk 66946) [x86_64-linux]
:foo
The script of [ruby-core:91323] uses method name "load_iseq" that is marked as "UNDEF". see r55656.
So I guess it is expected behavior, but I don't know the reason.
Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago
- Status changed from Open to Closed
As wanabe pointed out, this isn't a bug. load_iseq
is undef
in the singleton class, which occurs before extended modules during method lookup. prepend
on the singleton class works because prepended modules on the singleton class occur before methods in the singleton class itself during method lookup. Calling super
in the prepended method results in a NoMethodError
.