安装 iCalendar gem 后出现重复的类名
我只是尝试处理 iCalendar gem,但似乎 iCalendar 有一个名为 Event
的类,并且我的应用程序也有一个名为 Event
的类,
我想有一种方法可以确定范围一个或另一个类名,但我只是不知道如何。
这是我想要做的示例:
Event.new
=> ActiveRecord 模型
Icalendar::Event.new
=> Icalendar 事件类
谢谢。
I just tried to deal with iCalendar gem, but it seems iCalendar has a class named Event
, and my app also have a class named Event
I guess there is a way to scope one or another class name, but i just don't know how.
Here's an example of what i'd like to do :
Event.new
=> ActiveRecord Model
Icalendar::Event.new
=> Icalendar Event class
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想要将
iCalendar
gem 包装在模块中,然后从Icalendar::CalEvent
等实例化吗?顺便说一句:您可以只使用名称
Event
,但会出现有关重新分配给常量的警告。Hoe about wrapping up the
iCalendar
gem in a module and then instantiating from e.g.Icalendar::CalEvent
or something?BTW: you could just use the name
Event
, but there will be a warning about reassigning to a constant.强制 ruby 在访问模型时通过
::Event.new
查找顶级类定义。在类名之前包含 :: 表示该类不在任何模块中,这与位于Icalendar
模块中的Icalendar::Event
不同。或者,如果 iCalendar 不提供命名空间,您可以为您的类执行此操作,将其定义为并
为您的模型使用
MyStuff::Event
,并为您的模型使用::Event
iCal 之一。Force ruby to look for top-level class definitions when accessing your model, via
::Event.new
. Including :: before class name signifies that class is not in any module, as opposed toIcalendar::Event
that is inIcalendar
module.Or, if iCalendar does not provide the namespace, you can do it for your class, defining it as
and using
MyStuff::Event
for your model, and::Event
for iCal one.