Created
November 2, 2008 11:44
-
-
Save brainopia/21688 to your computer and use it in GitHub Desktop.
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
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