Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple prepend on the same class is broken #3225

Closed
dabroz opened this issue Oct 12, 2016 · 3 comments
Closed

Multiple prepend on the same class is broken #3225

dabroz opened this issue Oct 12, 2016 · 3 comments

Comments

@dabroz
Copy link
Contributor

@dabroz dabroz commented Oct 12, 2016

Normally I can define the same class multiple times. However if one of its included modules uses prepend to add some features, the class gets broken. Observe this code:

module Foo
  module Initializer
    def initialize
      puts 'pre-initialize'
      super
      puts 'post-initialize'
    end
  end

  def self.included(klass)
    klass.send :prepend, Initializer
  end
end

class Module
  def has_foo
    include Foo
  end
end

class Bar
  has_foo
  def initialize
    puts 'Bar.initialize'
  end
end

class Bar # this is repeated intentionally
  has_foo
  def initialize
    puts 'Bar.initialize'
  end
end

Bar.new

If I run this code under regular Ruby (ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]), I'm getting:

pre-initialize
Bar.initialize
post-initialize

However, when run under mruby (latest from master), I'm getting an error:

trace:
    [1] test.rb:28
    [0] test.rb:27
test.rb:28: undefined method 'has_foo' for #<Bar:0x7fb52c0077c0> (NoMethodError)

mruby works fine if I remove the duplicate of Bar. However this is not possible in the system I'm developing (which relies on dynamic reloading of files).

@bovi
Copy link
Member

@bovi bovi commented Oct 25, 2016

@matz is this intentional? if yes we should add it to mruby's limitation

@matz
Copy link
Member

@matz matz commented Oct 25, 2016

No, I will fix. But I can't say about when.

@matz matz closed this as completed in 4f6cce0 Nov 14, 2016
@dabroz
Copy link
Contributor Author

@dabroz dabroz commented Nov 14, 2016

Thanks! I can confirm this has fixed my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants