aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/option_merger.rb
blob: 51a2ea1328ccba0fb1de3072194030c0518b5449 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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