Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Last active Aug 29, 2015
Embed
What would you like to do?
if ARGV.count > 2
puts 'ERROR - Wrong arguments'
puts 'Usage: `ruby grid.rb <size> <grid_padding>`'
exit
end
size = (ARGV[0] || 10).to_i
grid_padding = (ARGV[1] || 2).to_i
grid = Array.new(size) { Array.new(size) { ['o', ' '].sample } }
border_partial = "+-#{'--' * grid_padding}"
border = "#{border_partial * size}+"
puts border
grid.each do |row|
row.each_with_index do |element, i|
print '|' if i == 0
print "#{' ' * grid_padding}#{element}#{' ' * grid_padding}"
print (i == size - 1 ? '|' : ' ')
end
puts
(grid_padding - 1).times do
print "|#{' ' * ((((grid_padding * 2) + 2) * size) - 1)}|\n"
end
end
puts border
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment