def replace_in_file(relative_path, *args, **options, &block)
      check_path(relative_path)
      contents = ::File.read(relative_path)
      replacement = (block ? block[] : args[1..-1].join).gsub('\0', '')
      match = Regexp.escape(replacement)
      status = nil

      log_status(:replace, relative_path, options.fetch(:verbose, true),
                                          options.fetch(:color, :green))
      return false if options[:noop]

      if options.fetch(:force, true) || !(contents =~ /^#{match}(\r?\n)*/m)
        status = contents.gsub!(*args, &block)
        if !status.nil?
          ::File.open(relative_path, 'w') do |file|
            file.write(contents)
          end
        end
      end
      !status.nil?
    end
def replace_in_file(relative_path, *args, **options, &block)
      check_path(relative_path)
      contents = ::File.read(relative_path)
      replacement = (block ? block[] : args[1..-1].join).gsub('\0', '')
      match = Regexp.escape(replacement)
      status = nil

      log_status(:replace, relative_path, options.fetch(:verbose, true),
                                          options.fetch(:color, :green))
      return false if options[:noop]

      if options.fetch(:force, true) || !(contents =~ /^#{match}(\r?\n)*/m)
        status = contents.gsub!(*args, &block)
        if !status.nil?
          ::File.open(relative_path, 'w') do |file|
            file.write(contents)
          end
        end
      end
      !status.nil?
    end
Replace content of a file matching string, returning false
 when no substitutions were performed, true otherwise.

 @param [String, Pathname] relative_path
 @options [Hash[String]] options
 @option options [Symbol] :force
   replace content even if present
 @option options [Symbol] :verbose
   log status

 @example
   replace_in_file('Gemfile', /gem 'rails'/, "gem 'hanami'")

 @example
   replace_in_file('Gemfile', /gem 'rails'/) do |match|
     match = "gem 'hanami'"
   end

 @return [Boolean]
   true when replaced content, false otherwise

 @api public