[Ironruby-core] Extending modules defined in a ruby library via C#

Daniele Alessandri suppakilla at gmail.com
Sat Jan 31 13:35:11 EST 2009


Hi,

I think I've stumbled on a bug of IronRuby, but I would like to hear
your thoughts about this before filing a report on the bug tracker as
I might be missing something or doing something wrong.

I have a ruby library in which is defined a module and this module
holds a few classes and constants. Then I wrote a library in C# where
the same module is defined to add more classes other than the ones
defined on the ruby side. Now if I load the assembly first and then i
require my ruby library everything works fine, but if I require the
ruby library first and then load the assembly, the module defined by
the ruby lib gets totally wiped off leaving there only what was
defined in the assembly.

Given that in similar scenarios we obviously can't use Extends =
typeof(...) in the RubyModuleAttribute, shouldn't modules previously
defined in ruby code be automatically extended instead of being
erased/redefined (which is definitely broken)? Right below here you
can find the code to reproduce and verify the reported behaviour (for
convenience I also made an attachment to this mail).



# =========== foo.rb ===========
def test(a)
  a.each{ |s| puts "#{s} is #{begin eval(s); rescue NameError;
'undefined' end}"}
end

module Foo
  class Bar; end
  VERSION = 1
end


/* ======== Nrk.Foo.Test.cs ======== */
namespace Nrk.Foo.Test {
    [RubyModule]
    public static class Foo {
        [RubyClass]
        public static class Hoge {
            [RubyMethod("piyo?", RubyMethodAttributes.PublicSingleton)]
            public static bool Piyo(Object self) {
                return true;
            }
        }
    }
}


# =========== test_assembly_first.rb ===========
load_assembly 'Nrk.Foo.Test', 'Nrk.Foo.Test'
require 'foo.rb'

test ['Foo', 'Foo::Bar', 'Foo::VERSION', 'Foo::Hoge', 'Foo::Hoge.piyo?']


# =========== test_ruby_first.rb ===========
require 'foo.rb'
load_assembly 'Nrk.Foo.Test', 'Nrk.Foo.Test'

test ['Foo', 'Foo::Bar', 'Foo::VERSION', 'Foo::Hoge', 'Foo::Hoge.piyo?']


# =========== OUTPUT #1 ===========
Foo is Foo
Foo::Bar is Foo::Bar
Foo::VERSION is 1
Foo::Hoge is Foo::Hoge
Foo::Hoge.piyo? is true

# =========== OUTPUT #2 ===========
Foo is Foo
Foo::Bar is undefined
Foo::VERSION is undefined
Foo::Hoge is Foo::Hoge
Foo::Hoge.piyo? is true


-- 
Daniele Alessandri
http://www.clorophilla.net/blog/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IR_TestCode.zip
Type: application/zip
Size: 1232 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090131/bf397af2/attachment.zip>


More information about the Ironruby-core mailing list