在IRB中使用ice_cube Ruby gem

6

我正在尝试在IRB中使用一个名为ice_cube的Ruby宝石,但它无法工作:

[~]$ rvm gemset create ice
'ice' gemset created (/home/joe/.rvm/gems/ruby-1.9.2-p320@ice).

[~]$ rvm gemset use ice
Using ruby-1.9.2-p320 with gemset ice

[~]$ gem install ice_cube
Fetching: ice_cube-0.8.0.gem (100%)
Successfully installed ice_cube-0.8.0
1 gem installed
Installing ri documentation for ice_cube-0.8.0...
Installing RDoc documentation for ice_cube-0.8.0...

[~]$ irb --simple-prompt
>> require 'ice_cube'
=> true

>> schedule = Schedule.new(Time.now)
NameError: uninitialized constant Object::Schedule
    from (irb):2
    from /home/joe/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'

我做错了什么?(我是一名初学者的Ruby程序员。)
3个回答

15

应该是这样的:

schedule = IceCube::Schedule.new(Time.now)

3
很多关于这个宝石的文档并没有明确表述这一点。 - Asher Walther
同意。这是一个相当明显的疏忽。 - stuartchaney
请参阅文档中的说明。 - Matteo

3
include IceCube
schedule = Schedule.new(Time.now)

或者你可以先将模块包含到全局命名空间中,然后就可以使用该模块中的任何内容。


0

有类似的问题,尝试重新启动Rails应用程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接