aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/option_merger.rb
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2005-12-15 20:03:23 +0000
committerSam Stephenson <sam@37signals.com>2005-12-15 20:03:23 +0000
commit85fe1ecaefe415ac1de36883f5f6162f49bd5287 (patch)
tree34f87cac51f7009928bc6ba0604cddf62be01d3e /activesupport/lib/active_support/option_merger.rb
parentfc4ffbdc69988b60bd17ffab5d8d81ec67a11180 (diff)
downloadrails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.tar.gz
rails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.tar.bz2
rails-85fe1ecaefe415ac1de36883f5f6162f49bd5287.zip
Add Object#with_options for DRYing up multiple calls to methods having shared options
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3314 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/option_merger.rb')
-rw-r--r--activesupport/lib/active_support/option_merger.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/option_merger.rb b/activesupport/lib/active_support/option_merger.rb
new file mode 100644
index 0000000000..51a2ea1328
--- /dev/null
+++ b/activesupport/lib/active_support/option_merger.rb
@@ -0,0 +1,25 @@
+module ActiveSupport
+ class OptionMerger #:nodoc:
+ instance_methods.each do |method|
+ undef_method(method) if method !~ /^(__|instance_eval)/
+ end
+
+ def initialize(context, options)
+ @context, @options = context, options
+ end
+
+ private
+ def method_missing(method, *arguments, &block)
+ merge_argument_options! arguments
+ @context.send(method, *arguments, &block)
+ end
+
+ def merge_argument_options!(arguments)
+ arguments << if arguments.last.respond_to? :merge!
+ arguments.pop.dup.merge!(@options)
+ else
+ @options.dup
+ end
+ end
+ end
+end