Skip to content

Instantly share code, notes, and snippets.

@nicholalexander
Created November 22, 2013 18:52
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 nicholalexander/7604950 to your computer and use it in GitHub Desktop.
Save nicholalexander/7604950 to your computer and use it in GitHub Desktop.
creating a custom array by inheriting and redefining...
class LifeBoardArray < Array
def [](index)
if index<=3
super(index)
elsif index > 3
super(index%4)
else
raise IndexError
end
end
def []=(index,obj)
if index<=3
super(index,obj)
elsif index > 3
super(index%4, obj)
else
raise IndexError
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment