Data Types

Data Types

Data types represent different types of data such as numbers, booleans, strings, etc. As an object-oriented language, all data types are based on classes.

Numbers

Ruby has different types of numbers such as integers and floating point numbers.

Loading...

Booleans

A value of either true or false.

Loading...

Strings

A string is a sequence of characters that represents a word or a sentence. They are created by surrounding a sequence of characters with single or double quotes.

Loading...

Arrays

Arrays store data in a list. An array can contain any type of data. Values are comma separated and enclosed in square brackets. Positions in the array start at 0.

Loading...

Hashes

A collection of key-value pairs enclosed within curly braces. Values are assigned to keys using the => syntax.

Loading...

Symbols

Symbols are a unique data type in Ruby. They are similar to strings except that they take up less memory and have better performance. Symbols are created by using the : syntax.

Loading...
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn Ruby on Codecademy