2012-05-02 22 views
8

my_gem hola nombre1 nombre2 nombre3 dame un my_gem hola¿Cómo se especifican varios argumentos o parámetros en Thor?

requiere al menos 1 argumento: my_gem hola nombre

¿Debo analizar ellos y separar los argumentos con un delimitador?

por ejemplo

my_gem hola nombre1, nombre2, nombre3, Namen

En el archivo se vería como

class MyCLI < Thor 
    desc "hello NAMES", "say hello to names" 

    def hello(names) 
    say "hello #{names.split(',')}" 
    end 
end 

O hay alguna forma de hacer esto?

Respuesta

12

Sí, hay otra forma de hacerlo.

require 'thor' 
class TestApp < Thor 
    desc "hello NAMES", "long desc" 
    def hello(*names) 
     say "hello #{names.join('; ')}" 
    end 
end 

Y se le puede llamar así:

$ thor test_app:hello first second third 
hello first; second; third 
+0

que también es conocido como el operador splat: http://stackoverflow.com/questions/4170037/what-does-the-star-mean -en-ruby y http://www.skorks.com/2009/08/method-arguments-in-ruby/ –

Cuestiones relacionadas