Reputation: 8119
I have recently shifted from writing my scripts in Bash to writing them in Ruby and I am curious if there is a conventional way to prompt for approval in Ruby? Normally in Bash I would use something similar to the following:
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
#The action
fi
I can think of a hundred ways to perform this type of check in Ruby but I am curious if there is a conventional way of doing so?
Upvotes: 1
Views: 1012
Reputation: 22830
Check out HighLine. HighLine provides a robust system for requesting data from a user, without needing to code all the error checking and validation rules and without needing to convert the typed Strings into what your program really needs. Just tell HighLine what you‘re after, and let it do all the work. It might be what you are looking for.
Upvotes: 2