I am playing with Shoes and Ruby and wanted to use the Math library on
my
simple Ruby program.
I tried putting the require stmt BEFORE the class MyClass and it did
not
work.
I then tried putting the require stmt BEFORE the Shoes.app
declaration,
and it did not work either.
Where should I put the require “Math” stmt listed below?
require “Math” and I also tried require ‘Math’
The following is basically my code structure:
class MyClass
def initialize
blah blah blah
end
def aMethod
more blah
end
end #MyClass
Shoes.app :title => “My Title”, :resizable => false do
flow :width => “100%”, :margin => 6 do
stack :width => “30%” do
blah blah
end
end
stack :width => "70%" do
blah blah blah
end
end # flow
Here is what works. This example only works when I add the keyword Math::.
That is the reason why I wanted to use require ‘Math’.
class MyClass
def initialize
# blah blah blah
end
def aMethod
# more blah
end alert Math::sqrt(81) #NOTE: If you do not add Math:: this does not
work!!!
v = 125
alert Math::sqrt(v)*
end #MyClass
Shoes.app :title => “My Title”, :resizable => false do
flow :width => “100%”, :margin => 6 do
stack :width => “30%” do
# blah blah para Math::sqrt(144)
end
end
stack :width => “70%” do
# blah blah blah
end
end
In that case, use include instead of require like this:
test.rb
include Math
class MyClass
def initialize; end
def aMethod; end
v = 125
alert sqrt(v)
end
Shoes.app :title => “My Title”, :resizable => false do
flow :width => “100%”, :margin => 6 do
stack :width => “30%” do
para sqrt(144)
end
end
stack :width => “70%” do
# blah blah blah
end
end