rubybuttonclickshoes

Ruby Shoes Button.click code does not execute after assignment of variable?


I ran into a problem that when I assign a variable button.click body it does not execute rest of the body.

Shoes.app do
@b1 = button("Open")
@b1.click{
    file= ask_open_file

    text= file.read
    alert "working?"
}
end

In above code alert will not execute but if you move it above the assignment statement it works. Can you help me?


Solution

  • file.read throws an exception, since file is a String. You probably want to read the file:

    Shoes.app do
      @b1 = button("Open")
      @b1.click{
        file= ask_open_file
    
        text= File.new(file).read
        puts text
        alert "working?"
      }
    end