There’s a reason Ruby is recommended to most beginners- and it happens to be readability. Ruby is hands-down one of the easiest-to-read languages.
A variable is nothing but a “term,” a “series of letters” or a “word” that is attributed to a certain specific value. For example, in the expression “ruby= 101,” the term “ruby” is a variable.
It’s as easy to type “ruby= 101” as it is to actually declare a variable in Ruby. All you need, now, is an example. Here’s an example of me declaring various variables in Ruby:
The term “ruby” stores the value “101,” the term “alphabet” stores the value “27,” and the term “thecyberfibre” stores the value “100.”
Is a “number” the only argument possible?
Certainly not. Ruby doesn’t limit variables’ arguments to numbers. Variables can be attributed as booleans, strings and symbols instead of numbers, as well.. Here’s an example of me attributing variables as booleans, strings and symbols respectively:
Remember, the arguments (or the values to the right of the equating symbol) for booleans are entered without either quotation marks to ratio symbols. For strings, using the double-quotation around arguments is essential. Similarly, using the ratio symbol before the argument for a symbol is necessary.
But what do the terms “boolean,” “string,” “symbol” and “float” mean?
All of the above, that is, the terms “boolean,” “string,” “symbol” and “float” are data types. Booleans have only two values, that is, “true” and “false.” Strings have values encompassing of a sequence of letters as the variable. Symbols are primitive data-types generally used for call-backs. The float data type is used when large (and complex) numbers (usually upto 7 digits) and decimals are to be dealt with.
Feel free to comment any questions with the help of the comment box embedded right below this post!
Discuss Ruby all you want in our Telegram group.
Featured Photo credit: "The Wanderer's Eye Photography" via Foter.com / CC BY-NC-SA