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).
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 :)
> 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.
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")
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.
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.
- 40 http://www.artima.com/forums/flat.jsp?forum=123&thread=139992
- 17 http://www.artima.com/buzz/community.jsp?forum=123
- 11 http://www.ruby-forum.com/topic/109820
- 7 http://www.ruby-forum.com/topic/113791
- 4 http://groups.google.ca/group/comp.lang.ruby/browse_thread/thread/f7298e15ea181eba/56ca9e4a09c7320e
- 2 http://search.yahoo.com/search?p=ruby inclusion&sp=1&fr2=sp-top&ei=UTF-8&fr=FP-tab-web-t&ei=UTF-8&SpellState=n-995860256_q-kNw3K75VklzzvWfe3ylKPQABAA@@
- 2 http://search.yahoo.com/search?p=class inclusion problem&fr=yfp-t-501-s&toggle=1&cop=mss&ei=UTF-8&vm=r
- 2 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/253430
- 2 http://www.ruby-forum.com/topic/111753
- 1 http://tw.search.yahoo.com/search?ei=UTF-8&u=b&fr=slv8-&p=double inclusion