Reduced Ruby Namespace Reduction

I am very new to ruby. I use IronRuby and my ruby ​​code has long namespaces:

Company:: Division::Group::Product::Package.new 

since I use this ns several times, is there a way to create a shortcut? In C #, I add a using clause, so I don't need to specify the full prefix.

+7
source share
2 answers

You can simply assign it to another constant, for example:

 Package = Company::Division::Group::Product::Package Package.new 
+13
source

You can also use the include method, which is larger than Ruby-esk:

 include Company::Division::Group::Product Package.new 

The difference between this and the current answer is that it pulls out all the constants in the namespace, where the current answer only pulls that name.

+5
source

All Articles