Ruby中类似Python的“as”关键字(用于命名空间)

时间:2022-05-03 22:30:58

I was just over looking at this question. The first thought that popped to my head was that ruby must have some sort of "as" type keyword like Python's import to help avoid namespace pollution. I've googled a bit but it seems that it's recommended to wrap your code in modules to avoid namespace problems with ruby. This seems problematic because what if two modules have conflicting names.

我只是在看这个问题。突然出现的第一个想法是,ruby必须有某种“as”类型的关键字,比如Python的导入,以帮助避免命名空间污染。我已经google了一下,但似乎建议将代码包装在模块中以避免ruby的命名空间问题。这似乎有问题,因为如果两个模块具有冲突的名称会怎样。

So, any "as" type keywords for ruby's require?

那么,ruby的任何“as”类型关键字都需要?

2 个解决方案

#1


2  

What I always do is start my modules with my company initials for work or my own initials for my personal projects.

我一直在做的是用我公司的姓名首字母开始我的模块工作或我个人项目的首字母缩写。

module JWG_TwitterTools
.
. 
.
end

#2


2  

In ruby 2.0, there will be mix (search for mix). But now, there is nothing like that... Simply use the full constant path.

在ruby 2.0中,将会混合(搜索混合)。但现在,没有类似的东西......只需使用完整的常量路径。

#1


2  

What I always do is start my modules with my company initials for work or my own initials for my personal projects.

我一直在做的是用我公司的姓名首字母开始我的模块工作或我个人项目的首字母缩写。

module JWG_TwitterTools
.
. 
.
end

#2


2  

In ruby 2.0, there will be mix (search for mix). But now, there is nothing like that... Simply use the full constant path.

在ruby 2.0中,将会混合(搜索混合)。但现在,没有类似的东西......只需使用完整的常量路径。