# CREDIT George Moschovitis 

# Creates a new file, or overwrites an existing file,
# and writes a string into it. Can also take a block
# just like File#open, which is yielded _after_ the
# string is writ.
#
#   str = 'The content for the file'
#   File.create('myfile.txt', str)
#
def File.create(path, str='', &blk)
  File.open(path, 'w') { |f|
    f << str
    blk.call(f) if blk
  }
end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  # mock file

  class File
    def self.open( fname, mode, &blk )
      blk.call( self )
    end
    def self.read( fname )
      @mock_content
    end
    def self.<<( str )
      (@mock_content ||="") << str
    end
  end

  class TC_CREATE < Test::Unit::TestCase

    def test_create
      f = "not a reasl file"
      t = 'This is a test'
      File.create( f, t )
      s = File.read( f )
      assert_equal( t, s )
    end

  end

=end

