【问题标题】:private method 'split' called for (Shoes::EditLine):Shoes::EditLine调用私有方法 'split' (Shoes::EditLine):Shoes::EditLine
【发布时间】:2009-08-28 01:46:10
【问题描述】:

我正在尝试编写一个简单的程序,该程序采用 rgb 值并使用 Shoes(Raisins 修订版 1134)将背景更改为该颜色。这是我的代码:

Shoes.app :title => "Show a Color" do

    def convert_to_num(value)
    # Splits string into numerical values
        value.split(',').map { |num| num.to_i }
    end 

    def to_rgb(value)
        red, green, blue = convert_to_num(value)
        rgb(red, green, blue)
    end  

    stack :height => 500, :width => 500 do
        value = edit_line
        button "Change color!" do
            background to_rgb(value)
        end
    end

end

当我运行它时,我得到了这个错误:私有方法“split”调用了 (Shoes::EditLine):Shoes::EditLine.为什么是这样?该方法在 irb 中有效。

【问题讨论】:

    标签: ruby shoes


    【解决方案1】:

    您试图在 EditLine 对象上拆分,而不是它的文本。您可以使用text 方法获取其文本,如下所示:

        def convert_to_num(value)
        # Splits string into numerical values
            value.text.split(',').map { |num| num.to_i }
        end
    

    【讨论】:

      【解决方案2】:

      我假设您希望 value 是一个字符串。您传递给to_rgbvalueShoes::EditLine,而不是字符串。我从看到错误消息而不是从阅读代码中知道这一点。您的 convert_to_num 方法很好,您只是没有将您认为的对象类型传递给它。

      我之前没有用 Shoes 编程,所以我不确定如何解决这个问题,但现在你至少知道是什么原因造成的了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多