From: Eric Schwartz Date: 2002-11-12T04:26:42+09:00 Subject: Re: [FAQ] Why use 'include' ts writes: > >>>>> "E" == Eric Schwartz writes: > > E> All this takes effect in the most restrictive lexical scope > E> available. If you do this inside a class definition, only that > E> class will be able to use the short forms. If you do it inside > E> another module definition, the entire module can use those short > E> forms. [ true? false? I'm not sure about this one. -- eric ] If > E> you do it at the top of a file, everything in that file can use the > E> short forms. > > Well, I've not understood what you are trying to say. Can you explain what > is "the most restrictive lexical scope available" ? That would be the tightest scope that applies. If you 'include' a module from inside a method, then you could only use the short forms inside the method's definition. If you do so inside a class, you can only use the short forms inside that class' scope (which is how mixins work). include'ing inside a module gives that entire module access to those short names, and so on. I think I may want to rewrite that bit to talk about namespaces, instead of lexical scopes, though. > pigeon% cat c.rb > module M > class A > end > end > > include M > pigeon% > > pigeon% cat b.rb > #!/usr/bin/ruby > require 'c' > p A.new > pigeon% > > pigeon% b.rb > # > pigeon% I'm not sure what this example is intended to illustrate. It certainly matches up with what I wrote. When the "require 'c'" code is executed, it loads c.rb. The last statement of c.rb is 'include M', which means that anybody 'require'ing c.rb will automatically import all the classes and methods (and variables) of module M into its current namespace. (Which I tried to indicate is often a bad idea, as a module writer.) -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton