【问题标题】:ruby can't dup Fixnumruby 无法复制 Fixnum
【发布时间】:2013-10-10 13:13:09
【问题描述】:

我有一些这样的代码

ssh_files = ["id_rsa.pub","id_rsa"]
ssh_files.each_with_index do |item, index|
      ssh_files[index] =  generate_ssh_path(creator).concat(item)
      FileUtils.mkdir_p(ssh_files[index], 0770) unless File.exists?(generate_ssh_path(creator))

结束 我收到此错误消息

TypeError (can't dup Fixnum):
  command.rb:45:in `block in generate_ssh_key'
  command.rb:42:in `each'
  command.rb:42:in `each_with_index'

在这里编辑堆栈

TypeError (can't dup Fixnum):
  command.rb:44:in `block in generate_ssh_key'
  command.rb:42:in `each'
  command.rb:42:in `each_with_index'
  command.rb:42:in `generate_ssh_key'
  key.rb:14:in `create_key'
  key.rb:10:in `initialize'
  app/models/user.rb:207:in `new'
  app/models/user.rb:207:in `ssh_key'

【问题讨论】:

  • ssh_files[file] 应为ssh_files[index]|index,file| 应为|file,index|
  • @ArupRakshit 我像你提议的那样改变了我现在收到这条消息 TypeError(没有将字符串隐式转换为整数):command.rb:43:in `[]='
  • @user1611830 嗯,我知道......命名约定只是显示错误的印象......就是这样。但是错误在其他地方..
  • @mbratch,我现在收到这条消息:TypeError(没有将字符串隐式转换为整数):command.rb:44:in `[]='
  • @mbratch 错误是我现在在帖子中指出的错误

标签: ruby-on-rails ruby


【解决方案1】:

mkdir_p 的选项应该是Hash,因为它接受多种选项,所以这样称呼它:

FileUtils.mkdir_p(ssh_files[index], :mode => 0770)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    相关资源
    最近更新 更多