public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added lambda merging to OptionMerger (especially useful with named_scope and 
with_options) [#740 state:committed] (Paweł Kondzior)
dhh (author)
Sat Nov 15 07:48:14 -0800 2008
commit  9eaa0a3449595d07fe2ada5c4c93ec226622147c
tree    9bf645cc94377fcdc49846c1aadddf6b2dab0702
parent  8d8195dc2443755786d3a8598b7c2da1f08a38e7
...
10
11
12
13
 
 
 
 
 
 
 
14
15
16
...
10
11
12
 
13
14
15
16
17
18
19
20
21
22
0
@@ -10,7 +10,13 @@ module ActiveSupport
0
 
0
     private
0
       def method_missing(method, *arguments, &block)
0
-        arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
0
+        if arguments.last.is_a?(Proc)
0
+          proc = arguments.pop
0
+          arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
0
+        else
0
+          arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
0
+        end
0
+
0
         @context.__send__(method, *arguments, &block)
0
       end
0
   end
...
64
65
66
 
 
 
 
 
 
 
 
67
68
69
...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -64,6 +64,14 @@ class OptionMergerTest < Test::Unit::TestCase
0
       end
0
     end
0
   end
0
+  
0
+  def test_nested_method_with_options_using_lamdba
0
+    local_lamdba = lambda { { :lambda => true } }
0
+    with_options(@options) do |o|
0
+      assert_equal @options.merge(local_lamdba.call),
0
+        o.method_with_options(local_lamdba).call
0
+    end
0
+  end
0
 
0
   # Needed when counting objects with the ObjectSpace
0
   def test_option_merger_class_method

Comments