Modules
Using module
To use a module, we have a use statement.
use mathThe above statement will load the math module. By default, this module return a map that contains its functions and properties.
puts math.abs(-20) // 20Like variable declaration, we can use multiple modules at one statement.
use math, io, taskAlias
Using module with another name, or many module have special name, alias is a great way to deal with them.
use m as 'math'
use my_math as 'this-is-my-custom-math'Creating module
Createa new file: my_num.no
return 100Use it in your code:
my_num.no returns a number, so my_num is a number, 100.
Of course, a function or any value works fine.
Notes
The variable is declared in use statement is immutable, so you cannot modify it.
If a module is not found, you will get a runtime error.
Last updated
Was this helpful?