我正在尝试学习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吗?