Created
May 20, 2016 16:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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