Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonleonhard/f16af27f28054b9ba572 to your computer and use it in GitHub Desktop.
Save jasonleonhard/f16af27f28054b9ba572 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# reads in user provided parameter for function like ./readsFile2ReadIn.rb file2ReadIn
filename = ARGV.first
# when user forgets to provide parameter in function call like: ./readsFile2ReadIn4.rb
while !filename # if !filename # wont repeat and we want to repeat
print "file? \n"
file_again = $stdin.gets.chomp
print "Oh you want file: #{file_again} \n" # shows filename file2ReadIn which is not important...
# print file_again.read
txt_again = open(file_again)
print txt_again.read # finally reads/opens file
end
# when user remembers to provide parameter: ./readsFile2ReadIn4.rb file2ReadIn
while filename
print "file is: #{filename}\n" # shows filename file2ReadIn which is not important...
file_again = open(filename)
print file_again.read
print "Do you want another file? \n" # shows filename file2ReadIn which is not important...
file_again = $stdin.gets.chomp # or # filename = gets.chomp
txt_again = open(file_again)
print txt_again.read
end
@jasonleonhard
Copy link
Author

./data_extractor.rb test.txt
Hello!

./data_extractor.rb
Please enter a filename
test.txt
Hello!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment