Command in the terminal:
ruby 1.rb key1 value1 key2 value2.
ie don’t have any options (–f, -v and etc.).
How to use the ‘Thor’ to get the arrays [key1, key2] and [value1,
value2]?
Can prompt another gem for this task?
Command in the terminal:
ruby 1.rb key1 value1 key2 value2.
ie don’t have any options (–f, -v and etc.).
How to use the ‘Thor’ to get the arrays [key1, key2] and [value1,
value2]?
Can prompt another gem for this task?
Do you mean that you will never need any other options ever, so the
parameters can always be processed this way?
Then you don’t need any gem. By default the arguments passed to your
program are placed in the ‘ARGV’ array and you only need to convert it
to Hash with some built-in method.
p ARGV.each_slice(2).to_h
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs