↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Input fields in rake task

The post starts from a Rake task that adds a new customer to a YAML file, then shows how to make the task interactive instead of hardcoding name and email values. It uses Ruby’s STDIN so the task can ask for input while it runs.

Reading notes
#

  • The task writes new customer data to a YAML file, but the name and email are fixed until the file is changed manually.
  • Ruby’s STDIN can be used to read user input during execution.
  • STDIN includes a trailing newline, so chomp is used to remove it.
  • The Rake task is updated to prompt for the customer name and email before saving.
  • The same approach can be used in other Ruby scripts, not only in Rake tasks.