tags:

views:

168

answers:

2

Hi. I am trying to write a simple program that takes a rgb value and changes the background to that color using Shoes (Raisins revision 1134). Here is my code:

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

When I run it, I get this error: private method 'split' called for (Shoes::EditLine):Shoes::EditLine. Why is this? The method works in irb.

+1  A: 

I assume you expect value to be a string. The value you pass to to_rgb is a Shoes::EditLine, and not a string. I know that from seeing the error message, not from reading the code. Your convert_to_num method is just fine, you just aren't passing the type of object you think you are to it.

I haven't programmed with Shoes before, so I'm not sure how to solve the problem, but now you know what's causing it at least.

August Lilleaas
+2  A: 

You are trying to split on the EditLine object, not its text. You can get its text using the text method, like this:

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