Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created May 20, 2016 16:53
Show Gist options
  • Save hackerdem/17c450132c1a12fdf7a31fa86b7bede8 to your computer and use it in GitHub Desktop.
Save hackerdem/17c450132c1a12fdf7a31fa86b7bede8 to your computer and use it in GitHub Desktop.
Ruby code for opening a file and truncating and after, recording new data
filename=ARGV.first
script=$0
puts "Data in the file named as #{filename} will be deleted"
puts "Press enter to continue"
print "? "
STDIN.gets
puts "Opening the file...."
target=File.open(filename,'w')
puts "Truncation the file"
target.truncate(target.to_s.size)
puts "Enter three lines to file"
print "name: ";name=STDIN.gets.chomp()
print "surname: ";surname=STDIN.gets.chomp()
print "number: ";number=STDIN.gets.chomp()
puts "your data will be written to file"
target.write(name)
target.write("\n")
target.write(surname)
target.write("\n")
target.write(number)
target.write("\n")
target.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment