如何删除一个宝石的多个副本?

我在程序上工作,我注意到它两次打印出此错误消息(尽管已在源代码中对其进行了修复,但仍继续这样做):

/Users/karenlee/Desktop/app_academy/Ruby/W5D4/minesweeper/board.rb:5: warning: previous definition of BOMB
 was here
board.rb:5: warning: already initialized constant Board::HIDDEN
/Users/karenlee/Desktop/app_academy/Ruby/W5D4/minesweeper/board.rb:5: warning: previous definition of HIDD
EN was here

我进行了一些挖掘,发现了以下解决方案:Rails 5.2.0 with Ruby 2.5.1 console - `warning:` `already` initialized constant FileUtils::VERSION

实质上声明要卸载然后更新fileutils gem。但是,当我尝试执行此操作时,出现以下错误消息:

ERROR:  While executing gem ... (Gem::InstallError)
    gem "fileutils" cannot be uninstalled because it is a default gem

我还查看了我的本地宝石列表,发现我还需要清理其他宝石的多个副本:

*** LOCAL GEMS ***

bigdecimal (default: 1.4.4,default: 1.3.4)
bundler (2.0.2,default: 1.17.3)
byebug (11.0.1)
cmath (default: 1.0.0)
coderay (1.1.2)
crass (default: 1.0.5)
csv (default: 3.1.2,default: 1.0.0)
date (default: 2.0.0,default: 1.0.0)
dbm (default: 1.0.0)
did_you_mean (default: 1.3.1)
etc (default: 1.0.1,default: 1.0.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.3.0,default: 1.0.2)
io-console (default: 0.4.8,default: 0.4.6)
ipaddr (default: 1.2.2,default: 1.2.0)
json (default: 2.2.0,default: 2.1.0)
loofah (default: 2.3.1)
method_source (0.9.2)
minitest (default: 5.13.0)
net-telnet (default: 0.2.0)
nokogiri (default: 1.10.5)
openssl (default: 2.1.2,default: 2.1.0)
power_assert (default: 1.1.5)
pry (0.12.2)
psych (default: 3.1.0,default: 3.0.2)
rake (default: 13.0.0)
rdoc (default: 6.2.0,default: 6.0.1)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
stringio (default: 0.0.2,default: 0.0.1)
strscan (default: 1.0.3,default: 1.0.0)
test-unit (default: 3.3.4)
tzinfo (default: 2.0.0)
webrick (default: 1.5.0,default: 1.4.2)
zeitwerk (default: 2.2.1)
zlib (default: 1.0.0)

我将如何卸载fileutils gem(希望该过程与我拥有的其他重复项类似)?如果我无法通过执行“ gem uninstall gem_name”来卸载默认的gems,还有另一种方法吗?

编辑 根据下面的评论请求,我将继续在下面发布我的“ board.rb”文件:

require_relative "tile"

class Board
    attr_reader :grid
    BOMB,HIDDEN = "?","⬜️"

    # initializes a new board with a grid of spaces
    def initialize
        @grid = self.make_board
    end

    # allows for easy access to positions on the board
    def [](pos)
        row,col = pos
        @grid[row][col]
    end

    # makes a new board (initializes) with the bombs placed
    def make_board
        # see the "new" ruby doc for Arrays; in one form of making a new array,# you can use the index as the parameter
        # just using one tile for testing purposes right now
        tile = Tile.new(self,[0,0])
        # Array.new(9) { | row | Array.new(9) { | col | Tile.new(self,[row,col]) } }
    end

    # randomly places bombs onto the grid
    # def place_bombs
    #     range = (0...@grid.length).to_a
    #     total_bombs = (@grid.length ** 2) / 4
    #     until @grid.flatten.map(&:value).count(BOMB) == total_bombs
    #         @grid[range.sample][range.sample].value = BOMB
    #         # @grid[range.sample][range.sample] = Tile.new(BOMB,self)
    #     end
    # end

    # # checks a position to see if it's a bomb
    # def is_a_bomb?(pos)
    #     row,col = pos
    #     @grid[row][col].value == BOMB
    # end

    # # checks if the entire board of non-bomb tiles are flipped over
    # def won?
    #     safe_tiles = @grid.flatten.select { | tile | tile.value == SAFE }
    #     safe_tiles.all? { | tile | tile.revealed }
    # end

    # # prints out board to the user
    # def render
    #     puts "   #{(0..8).to_a.join("   ")}"
    #     puts
    #     @grid.each.with_index do | row,row_indx |
    #         print "#{row_indx}  "
    #         row.each do | tile |
    #             if tile.revealed
    #                 print "#{tile.value}   "
    #             else  
    #                 print "#{HIDDEN}   "
    #             end
    #         end
    #         puts
    #         puts
    #     end
    # end
end

# board = Board.new
# p require_relative "tile"
# p board.grid

关于我如何运行程序,我正在使用Visual Studio Code,并通过在Visual Studio内部提供的终端屏幕的命令行上键入“ ruby​​ board.rb”来运行它。

roccp423 回答:如何删除一个宝石的多个副本?

如果我是你,我将删除我所有的宝石。

gem uninstall -aIx

然后使用创建一个名为.ruby-version的新文件

ruby-2.6.4

和另一个名为.ruby-gemset的文件,

app_academy

然后安装rvm,并与gemset和Bundler一起管理依赖性。

本文链接:https://www.f2er.com/3134829.html

大家都在问