【问题标题】:Ruby Haml Variable VariablesRuby Haml 变量
【发布时间】:2014-02-16 18:53:22
【问题描述】:

我正在使用 Ruby,我正在尝试使用变量变量名:D

while count < iterationnumber.to_i
        @output = testtrim[count].tr(",", " ").delete('{').delete('}').delete('"').delete('[').delete(']')
        count +=1
end

我需要在@output 中添加“count”,而不是只为haml 获得一个输出。另外,如果您知道如何更有效地去除所有这些字符,我将不胜感激。

提前致谢!

本尼

更新

   get '/test' do
   keygen = "#{session["keygen"]}"
   puts keygen
    template = Addressable::Template.new("http://api.toodledo.com/2/tasks/get.php?key=#{keygen};modafter=1234567890;fields=folder,star,priority")
    uri = template7.expand({"keygen" => keygen})
    puts uri
    responseauth = RestClient.get(uri.to_s)
    testtrim = responseauth.split('}')
    iterationnumber = testtrim[0][22..-2]
    count = 0
    while count < iterationnumber.to_i
        @output = testtrim[count].tr(",", " ").delete('{}"[]')
        count +=1
    end

现在的问题是,我不知道如何将“count”数字添加到@output,以将所有这些拆分部分输出到haml。也许有人知道更好的方法来做到这一点......

谢谢

【问题讨论】:

  • 你应该包含更多关于你想要做什么的信息。 testtrim 是什么?它包含什么?你想从中产生什么? countiterationnumber 是什么?

标签: ruby variables sinatra haml


【解决方案1】:

如下写

 @output = testtrim[count].tr(",", " ").delete('{}"')

无需按照文档调用#delete 方法链:

delete([other_str]+) → new_str

返回 str 的副本,其中 其参数交集的所有字符已删除。

【讨论】:

    猜你喜欢
    • 2014-03-16
    • 1970-01-01
    • 2011-10-03
    • 2013-10-15
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-05
    • 1970-01-01
    相关资源
    最近更新 更多