From 9eaa0a3449595d07fe2ada5c4c93ec226622147c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 15 Nov 2008 16:48:14 +0100 Subject: =?UTF-8?q?Added=20lambda=20merging=20to=20OptionMerger=20(especia?= =?UTF-8?q?lly=20useful=20with=20named=5Fscope=20and=20with=5Foptions)=20[?= =?UTF-8?q?#740=20state:committed]=20(Pawe=C5=82=20Kondzior)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activesupport/lib/active_support/option_merger.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/option_merger.rb') diff --git a/activesupport/lib/active_support/option_merger.rb b/activesupport/lib/active_support/option_merger.rb index b563b093ed..63662b75c7 100644 --- a/activesupport/lib/active_support/option_merger.rb +++ b/activesupport/lib/active_support/option_merger.rb @@ -10,7 +10,13 @@ module ActiveSupport private def method_missing(method, *arguments, &block) - arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup) + if arguments.last.is_a?(Proc) + proc = arguments.pop + arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) } + else + arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup) + end + @context.__send__(method, *arguments, &block) end end -- cgit v1.2.3