A question about require when using Shoes

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

end #Shoes

Thank you

On 10/18/2010 12:49 PM, Ruby S. wrote:

end #MyClass
end
end # flow
end #Shoes

Thank you

The Math library is always available, you do not need to require it.
Did you try just using it?

-Justin

I think Justin is right, in that you should be able to just use Math,
but if you need to require a gem, the proper way is with Shoes.setup:

Gents,

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

Thank you

Ruby S. [email protected] wrote:

*alert Math::sqrt(81) #NOTE: If you do not add Math:: this does not

work!!!*

True, but that is not the same as “requiring” Math. You’ll notice you
did not say “require” anywhere.

If the problem is that you don’t understand that a Module is a
namespace, you might find this discussion helpful:

http://www.apeth.com/rubyIntro/justenoughruby.html

It also explains what “require” means. m.

Hi Ruby S.,

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

Hope this helps,
ashbb

Matt,

Thank you for educating me. I am still learning!
Also, thank you for the link you gave me, “Just Enough Ruby”, it appears
interesting!

That said, I tried to save typing by using require ‘Math’, which did
not
work due to my obvious lack of knowledge.

Thank you

Hi ashbb,

That “include Math” stmt worked fine.
I truly appreciate your help.

Thank you

Ruby S. [email protected] wrote:

Thank you for educating me. I am still learning!
Also, thank you for the link you gave me, “Just Enough Ruby”, it appears
interesting!

That said, I tried to save typing by using require ‘Math’, which did not
work due to my obvious lack of knowledge.

The way to save typing is to include, not require. So:

include Math
puts PI #=> 3.14159265358979

All of that is explained in the “Just Enough Ruby” document.

m.