This is the first in a series for beginners on the Ruby Programming Language. Note that Ruby is a programming language. Ruby on Rails (“RoR”) is a web-application framework that is implemented in Ruby. Do not confuse the two. We will not covering Ruby on Rails in these tutorials.
These tutorials will be gather together under the tag #RubyTuesday, as we will be posting one each week from today to the end of term. Ready? Here we go…
# Variables and expressions.
a = 10
b = 3 * a + 2
printf("%d %d\n", a, b);
# Type is dynamic.
b = "A string"
c = 'Another String'
print b + " and " + c + "\n"
The variables shown in this example are “local variables”. (We’ll explore other possibilities later.)
Names are mostly conventional: letters, underscore, and digit, not starting with a digit. Local variables must start with a lower-case letter.
Variable types are dynamic: Assignment transfers both and type, not just value. Variables are not declared with a type, and assignment does not need to perform conversion.
+ concatenates strings, as in Java and C++.
printf function is lifted from plain C.