2010-05-23 47 views
1

我在Ruby中使用Highline时遇到了一些问题,并试图让选择元素detailed here工作。获取'选择'在Highline Ruby Gem中工作而没有错误并且从中变得可变

  1. 在下面的代码产生错误 的时刻“的错误:错误的参数数目(0 1)使用--trace查看回溯。”
  2. 我怎么变出来的选择?目前我有'做'设置,但我不知道如何获得用户选择的变量并将其用于其他地方使用的变量。

对不起,如果这是一个初学者,我是全新的红宝石,这是我的第一个项目,在深处。

在此先感谢。

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 
+0

哪线给你一个问题,到底是什么? 'choose'部分在Ruby 1.8或1.9中正常工作。 'ask_for_date'似乎是一个自定义的方法,因为'ask_for_array',所以不能帮你在那里... – 2010-05-23 15:01:00

+0

这是我的会话记录: \t Alex-Andrewss-MacBook-Pro:SoundCloud- CLI alex $ ruby​​ sc.rb上传/用户/ alex/SoundCloud-CLI \t这些文件将成为集合的一部分吗? ÿ \t名称:你好 \t描述: \t你好 \t类型:你好 \t唱片:你好 \t发行日期(年 - 月 - 日):10年9月10日 \t EAN/UPC:你好 \t购买此套件链接:你好 \t标签(空格隔离):你好好友 \t错误:参数数量错误(0代表1)。使用 - 跟踪查看回溯 非常感谢您的帮助。 – Alex 2010-05-23 19:47:56

回答

1

1)未提供足够的信息(见我的评论)

2)使用块参数:

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

您也可以分割你的选择:

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

menu.choice(:cc_by) do 
    puts "Chosen: CC by" 
    #... 
end 
+0

2)的解决方案非常好,谢谢。 关于1)我将以下内容复制到新文件中。 要求'rubygems' 要求'指挥官/进口' 选择做|菜单| menu.prompt = “请选择此设置许可证?” menu.choices(:all_rights_reserved,:cc_by)做|选择| 看跌期权 “项目中选择:#{}选择” 端 端 这失败,出现以下错误: scratch.rb:5:在'选择':错误的参数数目(0 1)(引发ArgumentError) 改变线路需要'指挥官',它的工作原理,但其他事情打破 – Alex 2010-05-23 20:10:05

相关问题