[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

"using namespace" equivalent ?

killy-kun

3/19/2006 2:28:00 PM

I would like to know if there is in ruby an equivalent to the c++
instruction "using namespace" (in order not to have to prefix things by
there namespace when needed).
2 Answers

James Gray

3/19/2006 3:59:00 PM

0

On Mar 19, 2006, at 8:28 AM, killy-kun wrote:

> I would like to know if there is in ruby an equivalent to the c++
> instruction "using namespace" (in order not to have to prefix
> things by there namespace when needed).

Well, if we are talking about a module, you might be able to include it:

>> module Namespace
>> extend self
>> def some_method
>> puts "Hello!"
>> end
>> end
=> nil
>> Namespace::some_method
Hello!
=> nil
>> include Namespace
=> Object
>> some_method
Hello!
=> nil

Hope that helps.

James Edward Gray II


killy-kun

3/19/2006 6:02:00 PM

0

James Edward Gray II wrote:
> On Mar 19, 2006, at 8:28 AM, killy-kun wrote:
>
>> I would like to know if there is in ruby an equivalent to the c++
>> instruction "using namespace" (in order not to have to prefix things
>> by there namespace when needed).
>
>
> Well, if we are talking about a module, you might be able to include it:
>
> >> module Namespace
> >> extend self
> >> def some_method
> >> puts "Hello!"
> >> end
> >> end
> => nil
> >> Namespace::some_method
> Hello!
> => nil
> >> include Namespace
> => Object
> >> some_method
> Hello!
> => nil
>
> Hope that helps.
>
> James Edward Gray II

Thank you very much !!
That's exactely what I was looking for.
(I was using the "require" instruction, and I thought the "include"
instruction was quite similar, that is why I didn't try it...)