Title: RE: [Wtr-general] test::unit question

Using "Head First Java" as a guide, here is one simplified way to think about modules, classes and methods:

Here is a module:
module MyModule

end

Q. What goes in a Module?
A. classes go in modules

module MyModule

class TestClass

end #of class

end  #of module

Q. What goes in a class?
A. methods go in classes

module MyModule

class TestClass

    def method1
      
    end #of method1  

end #of class

end  #of module

Q. What goes in a method?
A. statements go in methods

module MyModule

class TestClass

    def method1
       statement1
       statement2
    end #of method1  

end #of class

end  #of module

Q. How do I access methods in a module?
A. Provide access to the source file: include 'my_module_file'

You might have more than one module in a file (or in memory), so we access the class in the module we want using a scope operator :: like this:

MyModule::TestClass

And create a new instance of the class like this:
new_class = MyModule::TestClass.new

Execute method1 like this:
new_class.method1




_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to