Class: Warbler::Gems

Inherits:
Hash
  • Object
show all
Defined in:
lib/warbler/gems.rb

Overview

A set of gems. This only exists to allow expected operations to be used to add gems, and for backwards compatibility. It would be easier to just use a hash.

Constant Summary collapse

ANY_VERSION =
nil

Instance Method Summary collapse

Constructor Details

#initialize(gems = nil) ⇒ Gems

Returns a new instance of Gems.



15
16
17
18
19
20
21
# File 'lib/warbler/gems.rb', line 15

def initialize(gems = nil)
  if gems.is_a?(Hash)
    self.merge!(gems)
  elsif gems.is_a?(Array)
    gems.each {|gem| self << gem }
  end
end

Instance Method Details

#+(other) ⇒ Object



27
28
29
30
# File 'lib/warbler/gems.rb', line 27

def +(other)
  other.each {|g| self[g] ||= ANY_VERSION }
  self
end

#-(other) ⇒ Object



32
33
34
35
# File 'lib/warbler/gems.rb', line 32

def -(other)
  other.each {|g| self.delete(g)}
  self
end

#<<(gem) ⇒ Object



23
24
25
# File 'lib/warbler/gems.rb', line 23

def <<(gem)
  self[gem] ||= ANY_VERSION
end