[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

I don't know why!!

Kyung won Cheon

8/8/2008 1:58:00 AM

-- test1.rb --

module M
module MM
class C
end

class D < MM::C
end

class E < MM::C; puts self; end
end
end

# => M::MM::E

-- test2.rb --

module M
module MM
class C
end

class D < MM::C
end

#class E < MM::C; puts self; end
end
end

M::MM.module_eval("class E < MM::C; puts self; end")

# => uninitialized constant M::MM::MM (NameError)

-- test3.rb --

module M
module MM
class C
end

class D < MM::C
end

#class E < MM::C; puts self; end
end
end

M::MM.module_eval("class E < C; puts self; end")

# => M::MM::E

###################
# test2.rb ???
###################
--
Posted via http://www.ruby-....

1 Answer

TPReal

8/9/2008 10:05:00 PM

0

On Aug 8, 3:57 am, Kyung won Cheon <kdrea...@gmerce.co.kr> wrote:
> -- test1.rb --
>
> module M
>   module MM
>     class C
>     end
>
>     class D < MM::C
>     end
>
>     class E < MM::C; puts self; end
>   end
> end
>
> # => M::MM::E
>
> -- test2.rb --
>
> module M
>   module MM
>     class C
>     end
>
>     class D < MM::C
>     end
>
>     #class E < MM::C; puts self; end
>   end
> end
>
> M::MM.module_eval("class E < MM::C; puts self; end")
>
> # => uninitialized constant M::MM::MM (NameError)
>
> -- test3.rb --
>
> module M
>   module MM
>     class C
>     end
>
>     class D < MM::C
>     end
>
>     #class E < MM::C; puts self; end
>   end
> end
>
> M::MM.module_eval("class E < C; puts self; end")
>
> # => M::MM::E
>
> ###################
> # test2.rb ???
> ###################
> --
> Posted viahttp://www.ruby-....

Well, it's simple, if you say MM::C inside an M::MM's module_eval,
then it means M::MM::MM::C, and this is undefined. When you say Temp
\dir from inside C:\Temp, then it means C:\Temp\Temp\dir.