开发者

Short namespace acronym in ruby

开发者 https://www.devze.com 2023-04-04 04:04 出处:网络
I\'m very new to ruby. I use IronRuby and my ruby code has long namespaces: Company:: Division::Group::Product::Package.new

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 t开发者_Go百科o create a shortcut? In c# I add a using clause so I'm not required to specify the full prefix.


You can simply assign it to another constant, like:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消