eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

The double inclusion problem

This is a limitation in Ruby's object model we might never get rid of, for efficiency reasons:

module A; end
class C; include A end
module B; def foo; "B#foo" end end
module A; include B end
class D; include A end

D.new.foo                                          # => "B#foo"
C.new.foo
# ~> -:8: undefined method `foo' for #<C:0xb7dee8b8> (NoMethodError)


That's quite a pity. There's a very efficient way to implement method advices in pure Ruby (faster than the define_method trick I first wrote about over 1 year ago, and also speedier than alias_method-based interception) with modules that unfortunately depends on the ability to include a module into proxy classes (ICLASSes).


matz rubyconf keynote - riffraff (12-12-2005 (Lun) 16:38:43)

didn't he said that he'd like to make module inclusion symbolic for ruby2 so that things like this would work? I love matz' ideas for modules in ruby2 :)

No Title - Anonymous (2005-12-09 (Fri) 12:17:41)

> I (and surely many others) have known this for a long time

Which is why I said "too".

That makes me curious though, how long have you been using Ruby?

As for the nomenclature, it's not like Matz decreed to Rubydom this is what we will call it. But in all our conversions including those with Matz and others that is what we called it and it's likely that no one's talked about it more or explored it as much as we have. So, you know, call it whatever you like. I'm just trying to promote a common terminology. I could care less about any "credit" --which is what I think others tend to think.


mfp 2005-12-09 (Fri) 16:55:38

I've been using Ruby since early 2002 IIRC (maybe late 2001?). "Dynamic Module Include Problem" seems specific enough an expression, I'll try to keep it in mind. Sorry if you found my reply harsh --- this is something one easily falls into when trying to be concise, especially when switching constantly between several languages. As for giving credit where credit is due: anyway, everything we might find was first discovered by some Japanese Rubyist, so it cannot really matter that much ;-) (PS: I need some mental effort to picture myself as a part of "others" or "them", since I don't really feel a "member of anything")

Dynamic Module Include Problem - trans (2005-12-09 (Fri) 09:16:29)

I'm guessing you came across this exploring a module-based cut implemenation. Peter Vanbroekhoven discovered this too and explored it in depth. It's since become known as the Dynamic Module Include Problem (or variations thereof). And you're right, it's not likely to go away. Peter pretty much concluded that it requires a complete reworking of how Ruby handles module inclusion to fix. Matz is aware of it and siad he fix if he could, but he also see no reasonble solution.


mfp 2005-12-09 (Fri) 11:35:12

I (and surely many others) have known this for a long time (before suby-ruby existed ;) but I bumped into it again when playing with modules to see how much of your RCR on cuts could be implemented in pure Ruby. I didn't know that nomenclature had been adopted in the meantime.

Last modified:2005/12/09 07:39:12
Keyword(s):[blog] [ruby] [module] [include] [advice]
References:[Ruby]