# File lib/active_record/base.rb, line 1098
        def with_scope(method_scoping = {}, action = :merge, &block)
          method_scoping = method_scoping.method_scoping if method_scoping.respond_to?(:method_scoping)

          if method_scoping.is_a?(Hash)
            # Dup first and second level of hash (method and params).
            method_scoping = method_scoping.dup
            method_scoping.each do |method, params|
              method_scoping[method] = params.dup unless params == true
            end

            method_scoping.assert_valid_keys([ :find, :create ])
            relation = construct_finder_arel(method_scoping[:find] || {})

            if current_scoped_methods && current_scoped_methods.create_with_value && method_scoping[:create]
              scope_for_create = if action == :merge
                current_scoped_methods.create_with_value.merge(method_scoping[:create])
              else
                method_scoping[:create]
              end

              relation = relation.create_with(scope_for_create)
            else
              scope_for_create = method_scoping[:create]
              scope_for_create ||= current_scoped_methods.create_with_value if current_scoped_methods
              relation = relation.create_with(scope_for_create) if scope_for_create
            end

            method_scoping = relation
          end

          method_scoping = current_scoped_methods.merge(method_scoping) if current_scoped_methods && action ==  :merge

          self.scoped_methods << method_scoping
          begin
            yield
          ensure
            self.scoped_methods.pop
          end
        end