class Grid::Grid
Attributes
grid[RW]
Public Class Methods
new(width, height, default = 0)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 8 def initialize(width, height, default = 0) row = [default] * width @grid = [] height.times do @grid << row.clone end self end
Public Instance Methods
fill_square(start_x, start_y, end_x, end_y, val)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 46 def fill_square(start_x, start_y, end_x, end_y, val) (start_y..end_y).each do |y| horizontal(start_x, end_x, y, val) end end
horizontal(start_x, end_x, y, val)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 26 def horizontal(start_x, end_x, y, val) (start_x..end_x).each do |x| input(x, y, val) end end
input(x, y, val)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 22 def input(x, y, val) @grid[y][x] = val[0] end
inspect()
click to toggle source
# File lib/welcome_to_the_grid.rb, line 17 def inspect grid = @grid grid.each {|g| puts g.join(' ')} end
square(start_x, start_y, end_x, end_y, val)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 38 def square(start_x, start_y, end_x, end_y, val) horizontal(start_x, end_x, start_y, val) horizontal(start_x, end_x, end_y, val) vertical(start_y, end_y, start_x, val) vertical(start_y, end_y, end_x, val) end
vertical(start_y, end_y, x, val)
click to toggle source
# File lib/welcome_to_the_grid.rb, line 32 def vertical(start_y, end_y, x, val) (start_y..end_y).each do |y| input(x, y, val) end end