Modules provide a structure to collect Ruby classes, methods, and constants into a single, separately named and defined unit.
# Modules solve conflicts by providing namespaces that can contain any number of classes,
# methods, and constants, and allow you to address them directly.:
module NumberStuff
def NumberStuff.random
rand(1000000)
end
end
module LetterStuff
def LetterStuff.random
(rand(26) + 65).chr
end
end
puts NumberStuff.random
puts LetterStuff.random
Related examples in the same category