Skip to content

Instantly share code, notes, and snippets.

@suan
Created August 16, 2013 06:46
Show Gist options
  • Save suan/6247795 to your computer and use it in GitHub Desktop.
Save suan/6247795 to your computer and use it in GitHub Desktop.
Simple Infinite Array Ruby implementation
class InfiniteArray < Array
def initialize(value)
super(1, value)
end
def [](index)
self.first
end
end
irb(main):011:0> a = InfiniteArray.new('str')
=> ["str"]
irb(main):012:0> a[999999]
=> "str"
irb(main):013:0> a.first
=> "str"
irb(main):014:0> a.last
=> "str"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment