Project

General

Profile

Bug #15572

`RubyVM::InstructionSequence` doesn't work with `extend`.

Added by ioquatix (Samuel Williams) 9 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:91323]

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

History

Updated by wanabe (_ wanabe) 9 months 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) 4 months 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.

Also available in: Atom PDF