Method: Hash#to_multimap
- Defined in:
- lib/multimap.rb
#to_multimap ⇒ Object
Generates multiset from self. In generated multiset, values associated with a key are defined by the result of Multiset.parse(values_in_self) .
(example) Key :a is associated with values one :x and one :y, and key :b is associated with values two :x
{:a => [:x, :y], :b => [:x, :x]}.to_multimap
selfを多重連想配列に変換し、その結果を返します。新しく生成される多重連想配列においてキーに割り当てられる値は、selfにおけるキーの値をMultiset.parseによって多重集合に変換したものとなります。
(例)キー:aには:xと:yが1個ずつ、キー:bには:xが2個割り当てられた多重連想配列
{:a => [:x, :y], :b => [:x, :x]}.to_multimap
478 479 480 481 482 |
# File 'lib/multimap.rb', line 478 def to_multimap ret = Multimap.new self.each_pair{ |key, val| ret[key] = val } ret end |