From: Robert Klemme Date: 2009-01-27T22:52:48+09:00 Subject: Re: Scope resolution operator 2009/1/25 Stefano Crocco : > Alle domenica 25 gennaio 2009, Daniel Waite ha scritto: >> (The code I will demonstrate is Rails-based, but the question is >> Ruby-based.) >> >> I'm familiar with the following: >> ActiveRecord::Base >> >> Basically says, look inside ActiveRecord for a class or module named >> Base. >> >> But what about the following: >> ::Attachment >> Does that basically say, no matter what scope you are in, jump to the >> highest level to look for the class or module named Attachment? > > According to "The Ruby Programming Language", ::Something is a shortcut for > Object::Something. The idea is that ::Something should look up a constant > called Something in the global scope, but since ruby doesn't truly have a > global scope, it looks it up in the Object class, which is the nearest thing > in ruby to a global scope. As an illustration: 14:52:57 ~$ ruby -e 'puts Object.constants.sort' ARGF ARGV ArgumentError Array Bignum Binding Class Comparable Continuation Data Dir ENV EOFError Enumerable Errno Exception FALSE FalseClass File FileTest Fixnum Float FloatDomainError GC Hash IO IOError IndexError Integer Interrupt Kernel LoadError LocalJumpError Marshal MatchData MatchingData Math Method Module NIL NameError NilClass NoMemoryError NoMethodError NotImplementedError Numeric Object ObjectSpace ... You see all the globally scoped classes (later on there will be String etc.). Notice also the nice element of self referentiality. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end