<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -159,16 +159,12 @@ module Liquid
     # fetches an object starting at the local scope and then moving up
     # the hierachy
     def find_variable(key)
-      @scopes.each do |scope|
-        if scope.has_key?(key)
-          variable = scope[key]
-          variable = scope[key] = variable.call(self) if variable.is_a?(Proc)
-          variable = variable.to_liquid
-          variable.context = self if variable.respond_to?(:context=)
-          return variable
-        end
-      end
-      nil
+      scope = @scopes[0..-2].find { |s| s.has_key?(key) } || @scopes.last
+      variable = scope[key]
+      variable = scope[key] = variable.call(self) if variable.is_a?(Proc)
+      variable = variable.to_liquid
+      variable.context = self if variable.respond_to?(:context=)
+      return variable
     end
 
     # resolves namespaced queries gracefully.</diff>
      <filename>lib/liquid/context.rb</filename>
    </modified>
    <modified>
      <diff>@@ -157,4 +157,16 @@ class VariableResolutionTest &lt; Test::Unit::TestCase
     assert_equal 'bazbar', template.render
   end
 
+  def test_hash_with_default_proc
+    template = Template.parse(%|Hello {{ test }}|)
+    assigns = Hash.new { |h,k| raise &quot;Unknown variable '#{k}'&quot; }
+    assigns['test'] = 'Tobi'
+    assert_equal 'Hello Tobi', template.render!(assigns)
+    assigns.delete('test')
+    e = assert_raises(RuntimeError) {
+      template.render!(assigns)
+    }
+    assert_equal &quot;Unknown variable 'test'&quot;, e.message
+  end
+
 end
\ No newline at end of file</diff>
      <filename>test/variable_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>09c0b3b3916d44e3a31062161019247d9ef451b4</id>
    </parent>
  </parents>
  <author>
    <name>Brian Candler</name>
    <email>b.candler@pobox.com</email>
  </author>
  <url>http://github.com/tobi/liquid/commit/cfe3e6f3be197da14a1976fccb83cc1a33bb3add</url>
  <id>cfe3e6f3be197da14a1976fccb83cc1a33bb3add</id>
  <committed-date>2009-06-06T08:16:06-07:00</committed-date>
  <authored-date>2009-06-06T08:04:22-07:00</authored-date>
  <message>Allow Hash with default value or default proc to be used</message>
  <tree>6f3ce3e52364954473c86f8cfb47530967e2abdf</tree>
  <committer>
    <name>Brian Candler</name>
    <email>b.candler@pobox.com</email>
  </committer>
</commit>
