Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created November 2, 2008 11:44
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 brainopia/21688 to your computer and use it in GitHub Desktop.
Save brainopia/21688 to your computer and use it in GitHub Desktop.
require 'forwardable'
module SingletonCollection
module Methods
extend Forwardable
def_delegators :@storage, *Array.instance_methods(inherited=false)
attr_accessor :current_index
def current
self[current_index]
end
end
def self.extended(singleton)
singleton.extend Methods
singleton.instance_variable_set :@current_index, 0
singleton.instance_variable_set :@storage, []
end
extended self
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment