views:

83

answers:

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
+1  A: 

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
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 endThis 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
The Warm Jets