tag:blogger.com,1999:blog-5611656633903981530.post6929936563092955604..comments2023-10-15T01:37:35.027-07:00Comments on Begin Rescue: Apparently code order matters in Rubypete higginshttp://www.blogger.com/profile/06164347683461976036noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5611656633903981530.post-39440824179809087362008-08-01T23:45:00.000-07:002008-08-01T23:45:00.000-07:00The "problem" is that ruby evaluates your code dyn...The "problem" is that ruby evaluates your code dynamically. So the moment you call "include InnerModule" you <B>are not</B> "declaring that this class will include the module", you <B>are</B> calling include with InnerModule (the implicit receiver--self--inside a class declaration is the class itself--this is how rails let's you call "has_many" or stuff like that). And, at the moment you call this, InnerModule doesn't exist in the OuterModule scope.<BR/><BR/>As malu said, this is not a language where a compiler can first evaluate what your symbols are and know what you're referring to. Since this is evaluated as you declare it, you actually do need to have things declared beforehand.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5611656633903981530.post-24111544324565473812008-08-01T15:49:00.000-07:002008-08-01T15:49:00.000-07:00In compiled languages as C/C++ etc it is normal th...In compiled languages as C/C++ etc it is normal that you need to define everything before you can use it somehow (yes, there are exceptions...).<BR/>I don't know how the Ruby interpreter intern works, but I guess it simply wants to include the module InnerModule as soon as it reads the include statement. At that time the module InnerModule isn't defined so the interpreter doesn't know what to do and throws an exception. But this exception is strange, shouldn't it be InnerModule and not OuterModule?<BR/><BR/>If someone knows the process the Ruby interpreter uses intern, I would like to learn a bit about it, espacially with this problem. :)maluhttps://www.blogger.com/profile/14809206105663504909noreply@blogger.com