Ruby is an object-oriented programming language that was created in 1993 by Yukihiro Matsumoto.
A Ruby class is the blueprint from which individual objects are created.
Comments are denoted by using a hash, or '#' before the text
Types of data used in the language include numbers, strings, ranges, arrays, and hashes.
- Array - list of elements in an order.
- Hashes - a collection of key-value pairs.
- Ranges - (0..9 would output 0 to 9) return a range of numbers or letters.
- String literals - created using the double quote character, ".
- Strings - string of characters sent from the server to the browser.
Ruby has several built-in methods. Some common ones include:
- .first, .second, .last - these are used to access elements.
- .length - this returns the length of a string/array.
- .empty? - used to determine whether or not a data field is empty.
- .include? - if a datatype includes anything in particular.
- .sort, .reverse, .shuffle - these are useful for organizing the data in arrays.
- Bang operator (!) can be used to mutate an array.
- Shovel operator (<<) used to add to arrays.
Interactive Ruby (IRb) is a shell used for experimenting with Ruby. It's a console that you can use for the language in your terminal.
A symbol is an object type that is often used in hashes. They are denoted with a colon, like :description
. The following is an example of how they would appear in a hash:
person = {:name =>"Sarah", :id =>20, :birthday_month =>"October"}