The object system

In Roo, everything except for functions are objects. The following points apply to objects:

  • They have a type
  • They respond to methods

Methods are functions that belong to an object. The Roo object system guarantees a way to know any object’s type and whether or not it responds to a particular method. The only way to query the internal state of an object is through the object’s methods.

var n
n.type # => Nothing.

var i = 10
i.type # => Number

i.responds_to?("some_method_name") # => True or False.

Since everything is an object you can even call methods on literals:

var name = "iron man".reverse # => "nam nori"
9.sqrt # => 3

# Slightly more complex - check if some text is an email address:
|[^@\s]+@[^@\s]+\.[^@\s]+|.matches?("") # => True

# Chain calls to your heart's content.
var t = True.to_text.reverse.uppercase # => EURT