SciRuby / iruby

Official gem repository: Ruby kernel for Jupyter/IPython Notebook
https://github.com/SciRuby/iruby
MIT License
901 stars 29 forks source link

Module Import in a Notebook #316

Open Kerilk opened 2 years ago

Kerilk commented 2 years ago

Hello,

I am experiencing an issue similar to https://github.com/SciRuby/iruby/issues/303

I made a small github repository to reproduce the issue in binder, but this also occurs on my ubuntu 21.10 using ruby v2.7.4p191.

Here is a link to the repository: https://github.com/Kerilk/test-ruby-binder And to the notebook: Module Import Notebook

Any idea of what I could be doing wrong here?

Thanks

mrkn commented 2 years ago

@Kerilk Thank you for reporting this issue. I confirmed that it is a bug that occurs only Ruby < 3.0. I'll fix it in the next version.

mrkn@mrkn-ubuntu2004:~/src/github.com/sciruby/iruby$ cat test.rb
module M
end

o = Object.new
o.extend M

o.define_singleton_method(:include) do |*args|
  M.include(*args)
end

module Foo
  def bar
    puts "baz"
  end
end

o.include(Foo)
o.bar

mrkn@mrkn-ubuntu2004:~/src/github.com/sciruby/iruby$ RBENV_VERSION=2.5 ruby -v test.rb
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
Traceback (most recent call last):
test.rb:18:in `<main>': undefined method `bar' for #<Object:0x000056020ffc99e8> (NoMethodError)

mrkn@mrkn-ubuntu2004:~/src/github.com/sciruby/iruby$ RBENV_VERSION=2.6 ruby -v test.rb
ruby 2.6.9p207 (2021-11-24 revision 67954) [x86_64-linux]
test.rb:18:in `<main>': undefined method `bar' for #<Object:0x00005568e0f47088> (NoMethodError)

mrkn@mrkn-ubuntu2004:~/src/github.com/sciruby/iruby$ RBENV_VERSION=2.7 ruby -v test.rb
ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
Traceback (most recent call last):
test.rb:18:in `<main>': undefined method `bar' for #<Object:0x000055805bca4bb8> (NoMethodError)

mrkn@mrkn-ubuntu2004:~/src/github.com/sciruby/iruby$ RBENV_VERSION=3.0 ruby -v test.rb
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
baz