I was working on my program and I noticed that it printed out this error message twice (and it continues to do so despite having fixed it in the source code):
/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
I did some digging around and I found this solution: Rails 5.2.0 with Ruby 2.5.1 console - `warning:` `already` initialized constant FileUtils::VERSION
Which essentially states to uninstall and then update the fileutils gem. However, when I try to do this I get this error message:
ERROR: While executing gem ... (Gem::InstallError)
gem "fileutils" cannot be uninstalled because it is a default gem
I've also taken a look at my list of local gems and I noticed that I have multiple copies of other gems that I need to clean up as well:
*** 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)
How would I go about uninstalling the fileutils gem (and hopefully the process is similar for the other duplicates that I have)? If I can't uninstall default gems by doing "gem uninstall gem_name", is there another way to do this?
EDIT Per the comment request below, I'll go ahead and post my "board.rb" file below:
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
As for how I'm running the program, I'm using Visual Studio Code and running it by just typing "ruby board.rb" on the command line of the provided terminal screen inside of Visual Studio.