Forum: Ruby "using namespace" equivalent ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8aaafaf40d3dc025f7df2e52c5facc23?d=identicon&s=25 killy-kun (Guest)
on 2006-03-19 15:28
(Received via mailing list)
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).
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-03-19 16:59
(Received via mailing list)
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
8aaafaf40d3dc025f7df2e52c5facc23?d=identicon&s=25 killy-kun (Guest)
on 2006-03-19 19:03
(Received via mailing list)
James Edward Gray II wrote:
>  >>   extend self
>  >> 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...)
This topic is locked and can not be replied to.