Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Looping with invocation #235

Closed
mattdbridges opened this Issue · 4 comments

2 participants

@mattdbridges

I have a setup similar to this one.

class App < Thor
  def setup
    5.times { |n| invoke :add,  [n] }
  end

  def add(param)
    puts param
  end
end

So I am expecting this output:

$ thor app:setup
0
1
2
3
4

But I only get this

$ thor app:setup
0

Why can I not invoke an action within a loop? Am I missing something?

@eventualbuddha
Collaborator

This is intentional. If your intention is to have add be a private utility method then I recommend wrapping it in a no_tasks block. To use it simply call the method using normal ruby method call semantics: add(n).

@mattdbridges

@eventualbuddha In a way, yes that is true, but I want to be able to run both commands from the command line like thor app:setup and thor app:add 2. I can just move the functionality into a no_tasks method which the command line method would call.

Thanks for the tip.

@eventualbuddha
Collaborator

You could also simply leave the add method as a task and call with without invoke.

@mattdbridges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.