Method: Xqsr3::Containers::MultiMap#each
- Defined in:
- lib/xqsr3/containers/multi_map.rb
#each(*defaults) ⇒ Object
Calls block once for each key-value pair, passing the key and each of its values in turn. If the values for a given key are empty and defaults is not empty, the block is invoked for that key (with defaults[0]) once
Exceptions
-
ArgumentErrorif more than 1defaultsis provided, or no block is given
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/xqsr3/containers/multi_map.rb', line 229 def each *defaults raise ArgumentError, "may only supply 0 or 1 defaults" if defaults.size > 1 raise ArgumentError, 'block is required' unless block_given? @inner.each do |key, values| if values.empty? && !defaults.empty? yield key, defaults[0] next end values.each { |value| yield key, value } end end |