# Operators are really method invocations.
a = 10
b = 3.*(a).+(2)
Kernel::printf("%d %d\n", a, b);
# Type is still dynamic.
b = String.new("A string")
c = 'Another String'
Kernel.print(b.+(" and ")::+(c).+("\n"))
For instance, ordinary integers are objects of the class
Fixnum. The numeric operations are methods. Ruby lets you write
3 * a, but what you’re really doing is invoking the
* method on the object
3, and you can write it that way
Kernel refers to a built-in module. A module is similar to a static class in Java. The builtin-in functions
printf are part of
Kernel. As far as we can tell, the
. operators are equivalent.
Of course, string constants are objects of class
String, and this is made explicit in the statement
b = String.new("A String");. Notice that
new is a method of class
String, rather than being an operator as in Java and C++.
We’ll usually use the more conventional syntax, but the heavy use of objects provides great flexibility. We’ll flex later.
More next week on #RubyTuesday