新手问题 已解决:关于 require 'FileUtils'

i5ting · 2014年01月28日 · 最后由 kgtonglousy 回复于 2014年02月08日 · 3636 次阅读

关于 require 'FileUtils'

发布 gem 的时候

不能放进去,放进去就报 warning

/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:93: warning: already initialized constant FileUtils::OPT_TABLE
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:93: warning: previous definition of OPT_TABLE was here
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:1293: warning: already initialized constant FileUtils::Entry_::S_IF_DOOR
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:1293: warning: previous definition of S_IF_DOOR was here
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:1556: warning: already initialized constant FileUtils::Entry_::DIRECTORY_TERM
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:1556: warning: previous definition of DIRECTORY_TERM was here
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:1558: warning: already initialized constant FileUtils::Entry_::SYSCASE
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:1558: warning: previous definition of SYSCASE was here
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:1677: warning: already initialized constant FileUtils::LOW_METHODS
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:1677: warning: previous definition of LOW_METHODS was here
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/FileUtils.rb:1683: warning: already initialized constant FileUtils::METHODS
/Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:1683: warning: previous definition of METHODS was here

但是当本地测试的时候,

ruby -Ilib bin/tocmd -d .

必须写 require 'FileUtils',不然就报错

bin/tocmd:55:in `block in <main>': uninitialized constant FileUtils (NameError)
    from /Users/sang/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/optparse.rb:880:in `initialize'
    from bin/tocmd:22:in `new'
    from bin/tocmd:22:in `<main>'

目前能查到的资料

see at http://amaras-tech.co.uk/article/123/warning%3A_already_initialized_constant

但是它没有解决这个问题

已接近,感谢 @zhangyuan

不在电脑旁没验证。但记得应该是 require 'fileutils' 吧。

你的电脑是 mac 文件名不区分大小写。所以大小写不同,会 require 多次。

#1 楼 @zhangyuan 谢谢啊,我去试试

3 楼 已删除
需要 登录 后方可回复, 如果你还没有账号请 注册新账号