Hello there, if you are like me, fresh out of college with a useless degree that will get you nowhere and are interested in trying something new, like coding. Then RUBY is the language for you. It is simple, and easy to understand.
Ruby was designed and developed in the mid 1990s by Yukihiro "Matz" Matsumoto. Yukihiro designed Ruby so that it will be easy to read and applicable by humans. Other programming languages focus are designed to make our machines run efficiently and more effective. According to Yukihiro, "They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves."
Let's start off with the basics. Like other programming languages Ruby has 6 data types: Strings, Numbers, Booleans, Symbols, Arrays, and Hashes. In order to find out what data type something is, you add .class to the end of the data.
1)Strings: A string is any combination of letter or number that is wrapped in single or double quotation marks. You can convert into a string using .to_s.
2)Numbers: A number can be an Integer or a Float. Integers are whole numbers, whereas Float contains a decimal. You can convert a string with a number inside into an Integer using .to_i or a Float using .to_f.
3)Booleans: Booleans are used in logic statement to determine whether something is True or False. In Ruby, everything is True, but False and nil. We can use comparison operators such as AND, OR, ==, ||, &&
4)Symbols: In Ruby a symbol is an object that represents names of instance variables, names of method, or names of classes. If there is a hello method, then there is a symbol :hello. You can call on a symbol anywhere in the app or program. You can convert a string into a symbol using .to_sym.
5)Arrays: Array is a list that can consist of all different kinds of data types. It is enclosed in square brackets []. There are different ways you can create an array.
Another way is by using Array()
6)Hashes: A hash is a key, value pair enclosed in curly brackets {}. They works like dictionaries, you can search for values by looking up the key and vice versa. There are also different ways you can create a hash.
Another way is by assigning a variable to Hash.new
These are the Ruby data types to get you started on your Ruby adventure. Happy coding!
Top comments (0)