Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Short namespace acronym in ruby

I'm 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 multiple times is there a way to create a shortcut? In c# I add a using clause so I'm not required to specify the full prefix.

like image 402
Yaron Naveh Avatar asked Sep 10 '11 16:09

Yaron Naveh


2 Answers

You can simply assign it to another constant, like:

Package = Company::Division::Group::Product::Package
Package.new
like image 81
numbers1311407 Avatar answered Oct 30 '22 13:10

numbers1311407


You can also use the "include" method, which is more Ruby-esk:

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

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

like image 31
Jimmy Schementi Avatar answered Oct 30 '22 15:10

Jimmy Schementi