How do I use “gets” on a rake task?

前端 未结 2 1778
栀梦
栀梦 2021-02-01 11:53

I get an error whenever I try to use the function gets within a rake task. Is there a way to make it work?

The error says, \"no such file or directory - (rake task name)

2条回答
  •  生来不讨喜
    2021-02-01 12:25

    The problem is that Kernel#gets (which is what you're calling if you just use gets by itself) assumes you're pulling from a file named by the arguments passed to Rake. That means gets tries to return the content of a file called [rake-task-here], which almost certainly doesn't exist.

    Try STDIN.gets.

提交回复
热议问题