Class: GeminaboxSecure::GemVersionCollection
- Inherits:
-
Object
- Object
- GeminaboxSecure::GemVersionCollection
- Includes:
- Enumerable
- Defined in:
- lib/geminabox-secure/gem_version_collection.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(gemdef) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(initial_gems = []) ⇒ GemVersionCollection
constructor
A new instance of GemVersionCollection.
Constructor Details
#initialize(initial_gems = []) ⇒ GemVersionCollection
Returns a new instance of GemVersionCollection.
4 5 6 7 |
# File 'lib/geminabox-secure/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/geminabox-secure/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/geminabox-secure/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/geminabox-secure/gem_version_collection.rb', line 23 def each(&block) @gems.sort_by{|name, versions| name }.each(&block) end |