33 lines
864 B
Ruby
33 lines
864 B
Ruby
# Nathan Hinton 1 Oct 2025
|
|
# Create a custom hash class for the universe.
|
|
|
|
|
|
# This will contain the universe hash inside it. It will allow for array type
|
|
# indexing as well as point type indexing
|
|
class UniverseHash
|
|
def initialize()
|
|
@universe_hash = {}
|
|
end
|
|
|
|
# Setter for values in the hash
|
|
def =[](key, value)
|
|
if key.class == Array
|
|
@universe_hash[key[0]] = {} if @universe_hash[key[0]].nil?
|
|
@universe_hash[key[0]][key[1]] = {} if @universe_hash[key[0]][key[1]].nil?
|
|
@universe_hash[key[0]][key[1]][key[2]] = value
|
|
else
|
|
raise NotImplementedError.new('You can only set based on point values.')
|
|
end
|
|
end
|
|
|
|
def [](key)
|
|
if key.class == Array
|
|
return @universe_hash[key[0]][key[1]][key[2]]
|
|
elsif key.class == Integer
|
|
return @universe_hash[key]
|
|
else
|
|
raise NotImplementedError
|
|
end
|
|
end
|
|
end
|