    # File lib/core/facets/file/rewrite.rb, line 64
      def self.rewrite!(name, mode = "") #:yield:
        unless block_given?
          raise(ArgumentError, "Need to supply block to File.rewrite")
        end

        if mode.is_a?(Numeric) then
          flag, mode = mode, ""
          mode += "b" if flag & File::Constants::BINARY != 0
          mode += "+" if flag & File::Constants::APPEND != 0
        else
          mode.delete!("^b+")
        end

        old_str = open(name, "r#{mode}") { |file| file.read } #rescue ""
        new_str = old_str.clone

        begin
          yield(new_str)
        ensure
          if old_str != new_str
            open(name, "w#{mode}") { |file| file.write(new_str) }
          end
        end
      end