Skip to content

Instantly share code, notes, and snippets.

@chendrix
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chendrix/95474995f6cef714d3ad to your computer and use it in GitHub Desktop.
Save chendrix/95474995f6cef714d3ad to your computer and use it in GitHub Desktop.
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