Ruby Basics Flashcards

1
Q

Name the different types of literals

A

‘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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is string interpolation?

A

Using double quotes allows for string interpolation: “My favorite number is #{a}!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a symbol?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an integer in Ruby?

A

An integer literal is a WHOLE NUMBER example: 1, 2, 3, 4, 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a float in Ruby?

A

a float literal is a decimal example: 2342.2342

How well did you know this?
1
Not at all
2
3
4
5
Perfectly