# File lib/caesars.rb, line 154
154:   def find_deferred(*criteria)
155:     
156:     # The last element is assumed to be the attribute we're looking for. 
157:     # The purpose of this function is to bubble up the hierarchy of a
158:     # hash to find it.
159:     att = criteria.pop  
160:     
161:     # Account for everything being sent as an Array
162:     # i.e. find([1, 2, :attribute])
163:     # We don't use flatten b/c we don't want to disturb nested Arrays
164:     if criteria.empty?
165:       criteria = att
166:       att = criteria.pop
167:     end
168:     
169:     found = nil
170:     sacrifice = nil
171:     
172:     while !criteria.empty?
173:       found = find(criteria, att)
174:       break if found
175: 
176:       # Nested Arrays are treated special. We look at the criteria from
177:       # right to left and remove the first nested element we find.
178:       #
179:       # i.e. [['a', 'b'], 1, 2, [:first, :second], :attribute]
180:       #
181:       # In this example, :second will be removed first.
182:       criteria.reverse.each_with_index do |el,index|
183:         next unless el.is_a?(Array)    # Ignore regular criteria
184:         next if el.empty?              # Ignore empty nested hashes
185:         sacrifice = el.pop
186:         break
187:       end
188: 
189:       # Remove empty nested Arrays
190:       criteria.delete_if { |el| el.is_a?(Array) && el.empty? }
191: 
192:       # We need to make a sacrifice
193:       sacrifice = criteria.pop if sacrifice.nil?
194:       break if (limit ||= 0) > 10  # A failsafe
195:       limit += 1
196:       sacrifice = nil
197:     end
198: 
199:     found || find(att)  # One last try in the root namespace
200:   end