Add utility to draw the state of a hash.

This commit is contained in:
Danila Fedorin 2020-12-07 18:31:33 -08:00
parent 6a0edb873b
commit a5e6c4c145
1 changed files with 17 additions and 0 deletions

View File

@ -54,6 +54,9 @@ struct Tuple(*T)
{ {% for t, i in T %} self[{{i}}].signum, {% end %} }
{% end %}
end
def abs
end
end
struct Number
@ -62,3 +65,17 @@ struct Number
self // self.abs
end
end
class Hash(K, V)
def draw(maps)
min_x, max_x = keys.minmax_of &.[0]
min_y, max_y = keys.minmax_of &.[1]
(max_y-min_y+1).times do |y|
(max_x-min_x+1).times do |x|
next unless has_key?({x,y})
print maps[self[{x,y}]]
end
puts
end
end
end