Ruby Basics Flashcards
Name the different types of literals
‘Hello, world!’ // string literal
375 // integer literal
3.141528 // float literal
true // boolean literal
{ ‘a’ => 1, ‘b’ => 2 } // hash literal
[ 1, 2, 3 ] // array literal
:sym // symbol literal
nil // nil literal
What is string interpolation?
Using double quotes allows for string interpolation: “My favorite number is #{a}!”
What is a symbol?
Ruby symbols are created by placing a colon (:) before a word.
Copy Code
# Examples of symbols
:name
:a_symbol
:“surprisingly, this is also a symbol”
Basically, a symbol is used when you want to reference something like a string but don’t ever intend to print it to the screen or change it. It is often referred to as an immutable (i.e. unchangeable) string. While not 100% technically correct, it is a useful mnemonic device for now.
What is an integer in Ruby?
An integer literal is a WHOLE NUMBER example: 1, 2, 3, 4, 5
What is a float in Ruby?
a float literal is a decimal example: 2342.2342