On 11/5/07, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
> >> I have a question about using Object as the receiver in the above line.
> >> Is there any specific reason you are using Object?
> >
> > It's a way of looking up constants in the scope of the top level
> > binding (the special Object known as 'main').
> >
>
> ... so are Module.const_get and Class.const_get:
>
> class Dog
> end
>
> module Stuff
>   Greeting = "hello"
> end
>
>
> MyConst = 10
>
> puts Module.const_get("Dog").new
> puts Module.const_get("Stuff")::Greeting
> puts Module.const_get("MyConst")
> puts
> puts Class.const_get("Dog").new
> puts Class.const_get("Stuff")::Greeting
> puts Class.const_get("MyConst")
>
> --output:--
> #<Dog:0x251c0>
> hello
> 10
>
> #<Dog:0x25148>
> hello
> 10
>
Hi,

This illustrates what I mean:

Greeting = "goodbye"

class Module
 Greeting = "hello"
end

class Class
 Greeting = "hi!"
end

puts Module.const_get("Greeting")
puts Class.const_get("Greeting")
puts Object.const_get("Greeting")
puts eval( "Greeting", TOPLEVEL_BINDING ) # for Ara ;)

--output--
hello
hi!
goodbye
goodbye

Regards,
Sean