Contents

Roo

Modules

Modules serve as a namespace for defining other classes, modules, methods and getters. They are an excellent way to reuse code and make creating libraries to share with other Roo users easy. Below is an example of a module as a namespace:

module HTML {
    class Parser {
        parse(text) {
            print("I don't know how to parse yet!")
        }
    }

    ampersand {
        return "&"
    }
        
    copyright {
        return "©"
    }
    
    wrap_in_tags(what, tag_name) {
        return "<" + tag_name + ">" + what + "</" + tag_name + ">"
    }
}

var parser = HTML.Parser()
parser.parse("something") # => "I don't know how to parse yet!"
HTML.copyright # => "&copy;"
HTML.ampersand # => "&amp;"
HTML.wrap_in_tags("Some text", "p") # => "<p>Some text</p>"