MΓ³dulo 24 Β· The Ruby Object Model β LecciΓ³n 3 de 6 Β· ~11 min
Scope & Visibility
Scope gates: where local variables live and die
Ruby has a crisp rule most languages blur: class, module, and def each open a brand-new local scope β a scope gate. A local variable defined outside does not leak in, and one defined inside does not leak out. (Blocks are the deliberate exception β they close over their surroundings, which is why each can see outer variables. That's module 25.)
In an interview, say: "
class,module, anddefare scope gates β they start a fresh local scope. Blocks are not gates; they close over the enclosing scope. That distinction is why a constant defined at the top of a class is visible in its methods but a local variable isn't."