For grouping together methods, classes, and constants, we make use of module.
Modules give you two major benefits:
1) prevents name clashes.
2) implement the mixin facility.
Syntax:
module Identifier
statement1
statement2
...........
end
Module constants are named with an initial uppercase letter
Example:
#!/usr/bin/ruby
# Module defined in trig.rb file
module Trig
PI = 3.141592654
def Trig.sin(x)
# ..
end
def Trig.cos(x)
# ..
end
end
0 Comment(s)