0

I have begun playing around with Shoes.rb and I have an hard time making the UI working with some logics. For instance I'd like to send a message to an object when a button is clicked so I have the following code:

    Shoes.app do
      button "Run" do
        @label.replace Calculator.add(1,1)
      end
      @label = para "Result will show up here"
   end

I have also my Calculator class

class Calculator
  def self.add(x,y)
    x+y
  end
end

How can I make it work? I have tried to add the class under the Shoes block (adding also it into a module) and having the class in a separate required file but nothing works.

Thanks.

Sig
  • 5,476
  • 10
  • 49
  • 89

1 Answers1

1

Put Calculator definition before the Shoes.app block:

class Calculator
  def self.add(x,y)
    x+y
  end
end

Shoes.app do
  button "Run" do
    @label.replace Calculator.add(1,1)
  end
  @label = para "Result will show up here"
end

Otherwise, code in the Shoes.app block can't access the Calculator class.

before click

after click

falsetru
  • 357,413
  • 63
  • 732
  • 636
  • Thanks, actually I was able also to require external file, I had a typo before. – Sig Jul 24 '14 at 14:31