Methods are public by default in Ruby.
Include module to class, so it will be available inside class and all the methods can be called without module name:
class TestModules are containers for methods and constants.
def public_m
end
private
def private_m
end
// Again private method, because all methods after private keyword will be private
def private_m_2
end
end
module MyModuleRequire module by typing require 'MyModule', so it will be available in whole file (Module.my_method)
// Call it: MyModule::MOD_CONSTANT
MOD_CONSTANT = "Module constat"
// Call it: MyModule.my_method
def my_method
end
end
Include module to class, so it will be available inside class and all the methods can be called without module name:
class SimpleClassInfromation from: www.codeacademy.com
include MyModule // Without '
def m
my_method
end
end
No comments:
Post a Comment