brainopia (owner)

Revisions

gist: 21688 Download_button fork
public
Public Clone URL: git://gist.github.com/21688.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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