1

I am looking at the first line of following rake task:

task :generate_course_group_progress_report => [:environment] do

Why is [:environment] passed as the value of the hash as an array instead of :environment? what does this do? This doesn't seem to break the task.

Is there a scenario where I would pass multiple variables to the hash, i.e [:environment, :something_else]?

Gerard Simpson
  • 2,026
  • 2
  • 30
  • 45
  • Your question "Why is [:environment] passed as the value of the hash instead of :environment?" is not clear. Are you asking why it is not passed without a hash like `task :generate_course_group_progress_report, [:environment]`, or are you asking why it is not passed without the array like `task :generate_course_group_progress_report => :environment`? – sawa Apr 19 '18 at 06:02
  • I'm asking why it is in array format instead of just the symbol on it's own – Gerard Simpson Apr 19 '18 at 06:07
  • If a rake task depends on multiple other tasks then you'd say `task :a => [:b, :c]` and `rake a` would run tasks `b` and `c` first. Perhaps some time with [the docs](https://github.com/ruby/rake/blob/master/README.rdoc) would be fruitful. – mu is too short Apr 19 '18 at 07:24

1 Answers1

1

No, you can use it also as a symbol.

task test_task: :environment do # some code end

Farhad
  • 131
  • 1
  • 1
  • 7
  • 2
    this is correct, but is not really a complete answer. If you know the purpose of :environment, you should briefly explain it, or at least link to some docs. – max pleaner Apr 19 '18 at 06:19
  • https://stackoverflow.com/questions/7044714/whats-the-environment-task-in-rake Maybe it can be helpful – Farhad Apr 19 '18 at 06:22
  • 2
    ok, thanks @Farhad, I'm not really asking because I'm confused, I'm just trying to let you know what an acceptable answer looks like. It's understandable that you don't know this having just joined the site. – max pleaner Apr 19 '18 at 06:24
  • Yeah, am new on board sorry :( Just trying to adapt. – Farhad Apr 19 '18 at 06:30
  • 1
    I know you can use it as a symbol, but what is the point of putting that symbol in an array? – Gerard Simpson Apr 19 '18 at 07:01