aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/object_and_class.rb4
-rw-r--r--activesupport/lib/active_support/option_merger.rb25
3 files changed, 30 insertions, 0 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 7d5440f2a8..1cace11e9b 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -32,5 +32,6 @@ require 'active_support/clean_logger'
require 'active_support/dependencies'
require 'active_support/ordered_options'
+require 'active_support/option_merger'
require 'active_support/values/time_zone' \ No newline at end of file
diff --git a/activesupport/lib/active_support/core_ext/object_and_class.rb b/activesupport/lib/active_support/core_ext/object_and_class.rb
index 7864c1a9dc..aef1f22c6f 100644
--- a/activesupport/lib/active_support/core_ext/object_and_class.rb
+++ b/activesupport/lib/active_support/core_ext/object_and_class.rb
@@ -50,6 +50,10 @@ class Object #:nodoc:
raise unless exception_classes.any? {|cls| e.kind_of? cls}
end
end
+
+ def with_options(options)
+ yield ActiveSupport::OptionMerger.new(self, options)
+ end
end
class Class #:nodoc:
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