无需重复的Ruby Rake数组选择任务

时间:2018-07-04 02:22:35

标签: ruby-on-rails arrays rake

我正在尝试学习Ruby并被困在一项繁重的任务上。每次运行rails fortune时,应该显示不同的命运吗? 我应该使用什么来确保随机选择永远不会背对背重复相同的响应?

    desc "Print a random fortune"
    task :fortune do
       fortunes = [
         "Do not mistake temptation for opportunity",
         "A friend asks only for your time not your money",
         "Do not confuse recklessness with confidence",
         "Bide your time, for success is near",
         "Every day in your life is a special occasion"]

              ap(fortunes.sample)
         end

我应该使用.each吗?

0 个答案:

没有答案