diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-15 16:48:14 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-15 16:48:14 +0100 |
commit | 9eaa0a3449595d07fe2ada5c4c93ec226622147c (patch) | |
tree | 9bf645cc94377fcdc49846c1aadddf6b2dab0702 /activesupport/lib | |
parent | 8d8195dc2443755786d3a8598b7c2da1f08a38e7 (diff) | |
download | rails-9eaa0a3449595d07fe2ada5c4c93ec226622147c.tar.gz rails-9eaa0a3449595d07fe2ada5c4c93ec226622147c.tar.bz2 rails-9eaa0a3449595d07fe2ada5c4c93ec226622147c.zip |
Added lambda merging to OptionMerger (especially useful with named_scope and with_options) [#740 state:committed] (Paweł Kondzior)
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/option_merger.rb | 8 |
1 files changed, 7 insertions, 1 deletions
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 |