Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

turn anonymous proc each_container_with_default into a real private

function
  • Loading branch information...
commit b92d33974933e3c0f3393b93ce98f8cd8d6aa1bc 1 parent a8d439c
Joshua Peek authored

Showing 1 changed file with 15 additions and 13 deletions. Show diff stats Hide diff stats

  1. 28  lib/nested_multimap.rb
28  lib/nested_multimap.rb
@@ -111,20 +111,11 @@ def each_association
111 111
   #   [100, 101, 102]
112 112
   #   [100, 102]
113 113
   #   []
114  
-  def each_container_with_default
115  
-    each_container = Proc.new do |container|
116  
-      if container.respond_to?(:each_container_with_default)
117  
-        container.each_container_with_default do |value|
118  
-          yield value
119  
-        end
120  
-      else
121  
-        yield container
122  
-      end
  114
+  def each_container_with_default(&block)
  115
+    @hash.each_value do |container|
  116
+      iterate_over_container(container, &block)
123 117
     end
124  
-
125  
-    @hash.each_pair { |_, container| each_container.call(container) }
126  
-    each_container.call(default)
127  
-
  118
+    iterate_over_container(default, &block)
128 119
     self
129 120
   end
130 121
 
@@ -148,6 +139,17 @@ def containers_with_default
148 139
   def inspect #:nodoc:
149 140
     super.gsub(/\}$/, ", default => #{default.inspect}}")
150 141
   end
  142
+
  143
+  private
  144
+    def iterate_over_container(container)
  145
+      if container.respond_to?(:each_container_with_default)
  146
+        container.each_container_with_default do |value|
  147
+          yield value
  148
+        end
  149
+      else
  150
+        yield container
  151
+      end
  152
+    end
151 153
 end
152 154
 
153 155
 begin

0 notes on commit b92d339

Please sign in to comment.
Something went wrong with that request. Please try again.