Class: MultiMail::Multimap
- Inherits:
-
Object
- Object
- MultiMail::Multimap
- Defined in:
- lib/multi_mail/multimap.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each_pair ⇒ Object
-
#initialize ⇒ Multimap
constructor
A new instance of Multimap.
- #merge(other) ⇒ Object
- #size ⇒ Object
- #to_hash ⇒ Object
- #update(other) ⇒ Object
Constructor Details
#initialize ⇒ Multimap
Returns a new instance of Multimap.
5 6 7 |
# File 'lib/multi_mail/multimap.rb', line 5 def initialize @hash = {} end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/multi_mail/multimap.rb', line 18 def ==(other) if Multimap === other @hash == other.hash else @hash == other end end |
#[](key) ⇒ Object
9 10 11 |
# File 'lib/multi_mail/multimap.rb', line 9 def [](key) @hash[key] end |
#[]=(key, value) ⇒ Object
13 14 15 16 |
# File 'lib/multi_mail/multimap.rb', line 13 def []=(key, value) @hash[key] ||= [] @hash[key] << value end |
#each_pair ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/multi_mail/multimap.rb', line 30 def each_pair @hash.each_pair do |key,values| values.each do |value| yield key, value end end end |
#merge(other) ⇒ Object
38 39 40 |
# File 'lib/multi_mail/multimap.rb', line 38 def merge(other) dup.update(other) end |
#size ⇒ Object
26 27 28 |
# File 'lib/multi_mail/multimap.rb', line 26 def size @hash.values.flatten.size end |
#to_hash ⇒ Object
53 54 55 |
# File 'lib/multi_mail/multimap.rb', line 53 def to_hash @hash.dup end |
#update(other) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/multi_mail/multimap.rb', line 42 def update(other) if Multimap === other other.each_pair do |key,value| self[key] = value end else raise ArgumentError end self end |