开发者

Getting 'choice' to work in Highline Ruby Gem without error and getting variable from it

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 (seper开发者_如何学Pythonated 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) 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜