Created
November 22, 2013 18:52
-
-
Save nicholalexander/7604950 to your computer and use it in GitHub Desktop.
creating a custom array by inheriting and redefining...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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