diff options
Diffstat (limited to 'activesupport/lib/active_support/option_merger.rb')
-rw-r--r-- | activesupport/lib/active_support/option_merger.rb | 25 |
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 |