Skip to content

Instantly share code, notes, and snippets.

@tra38
Created January 16, 2016 21:21
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 tra38/44666adbf946cc2b2609 to your computer and use it in GitHub Desktop.
Save tra38/44666adbf946cc2b2609 to your computer and use it in GitHub Desktop.
class OutOFBoundsException < RuntimeError
end
class FixedArray
def initialize(size)
@size = size
size.times do |index|
self.instance_variable_set(:"@index#{index}", nil)
end
end
def get(index)
if instance_variable_defined?(:"@index#{index}")
self.instance_variable_get("@index#{index}")
else
raise OutOFBoundsException
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment