1

I'm having a couple of problems using Highline in Ruby, and trying to get the choice element, detailed here, to work.

  1. At the moment the following code produces the error "error: wrong number of arguments (0 for 1). Use --trace to view backtrace"
  2. How do I get the variable out of choice? At the moment I have the 'do' setup, but I have no idea about how to get the variable the user has chosen out and into a variable for use elsewhere.

Sorry if this is a bit beginner, I'm brand new to ruby and this is my first project, in at the deep end.

Thanks in advance.

if agree("Are these files going to be part of a set? ") 
      set_title = ask("Title: ")
      set_desc = ask("Description:")
      set_genre = ask("Genre: ")
      set_label = ask("Record Label: ")
      set_date = ask_for_date("Release Date (yy-mm-dd): ")
      set_label = ask("EAN/UPC: ")
      set_buy = ask("Buy this set link: ")
      set_tags = ask_for_array("Tags (seperated by space): ")

      # Sort out license
      choose do |menu|
        menu.prompt = "Please choose the license for this set?  "

        menu.choices(:all_rights_reserved, :cc_by) do 
          # put the stuff in a variable
        end
      end
    end # End setup set
Alex
  • 193
  • 2
  • 2
  • 9
  • Which line gives you a problem, exactly? The `choose` section works fine in Ruby 1.8 or 1.9. The `ask_for_date` seems to be a custom method, as is `ask_for_array`, so can't help you there... – Marc-André Lafortune May 23 '10 at 15:01
  • This is a transcript of my session: Alex-Andrewss-MacBook-Pro:SoundCloud-CLI alex$ ruby sc.rb upload /Users/alex/SoundCloud-CLI Are these files going to be part of a set? y Title: hello Description: hello Genre: hello Record Label: hello Release Date (yy-mm-dd): 09-10-10 EAN/UPC: hello Buy this set link: hello Tags (seperated by space): hello gello error: wrong number of arguments (0 for 1). Use --trace to view backtrace Thanks very much for your help so far. – Alex May 23 '10 at 19:47

1 Answers1

1

1) Not enough information provided (see my comment)

2) Use a block parameter:

menu.choices(:all_rights_reserved, :cc_by) do |chosen|
  puts "Item chosen: #{chosen}"
end

You can also split your choices:

menu.choice(:all_rights_reserved) do
  puts "Chosen: All Rights Reserved"
  #...
end

menu.choice(:cc_by) do
  puts "Chosen: CC by"
  #...
end
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
  • The solution to 2) works beautifully thanks. With regard to 1) I copied the following to a fresh file. require 'rubygems' require 'commander/import' choose do |menu| menu.prompt = "Please choose the license for this set? " menu.choices(:all_rights_reserved, :cc_by) do |chosen| puts "Item chosen: #{chosen}" end end This fails with the following errors: scratch.rb:5:in `choose': wrong number of arguments (0 for 1) (ArgumentError) Change the line to require 'commander' and it works, but other things break – Alex May 23 '10 at 20:10