Class: Strangebox::GemVersionCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/strangebox/gem_version_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial_gems = []) ⇒ GemVersionCollection

Returns a new instance of GemVersionCollection.



4
5
6
7
# File 'lib/strangebox/gem_version_collection.rb', line 4

def initialize(initial_gems = [])
  @gems = Hash.new{|h,k| h[k] = [] }
  initial_gems.each{|g| self << g }
end

Instance Method Details

#+(other) ⇒ Object



17
18
19
20
21
# File 'lib/strangebox/gem_version_collection.rb', line 17

def + other
  other.inject(self.class.new(self)){|new_set, gemdef|
    new_set << gemdef
  }
end

#<<(gemdef) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/strangebox/gem_version_collection.rb', line 9

def <<(gemdef)
  name,version,_ = gemdef
  return self if name.nil?
  @gems[name] += [version].flatten
  @gems[name].sort!
  self
end

#each(&block) ⇒ Object



23
24
25
# File 'lib/strangebox/gem_version_collection.rb', line 23

def each(&block)
  @gems.sort_by{|name, versions| name }.each(&block)
end