8

my_gem ciao nome1 nome2 NAME3 darmi unaCome si specificano più argomenti o parametri in Thor?

my_gem ciao richiede almeno 1 argomento: my_gem ciao nome

Devo semplicemente analizzare e separare gli argomenti con un delimitatore?

es

my_gem ciao nome1, nome2, NAME3, Namen

Nel file sarebbe simile

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

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

O Esiste un modo per fare questo?

risposta

12

Sì, c'è un altro modo per farlo.

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

E può essere chiamato in questo modo:

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

che è anche conosciuto come l'operatore splat: http://stackoverflow.com/questions/4170037/what-does-the-star-mean -in-ruby e http://www.skorks.com/2009/08/method-arguments-in-ruby/ –