Skip to content

Instantly share code, notes, and snippets.

@chendrix
Last active August 29, 2015 14:14
Embed
What would you like to do?
Multiple constructors
class Minefield
def initialize(map)
@map = map
end
def self.initialize_with_random_mines(size: , mine_count:)
map = Array.new(size) { Array.new(size) { Cell.new } }
mine_count.times do |_|
row = rand(size)
col = rand(size)
unless map[row][col].has_mine?
map[row][col].place_mine
end
end
self.new(map)
end
private
attr_reader :map
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment