Ruby conventions Flashcards

1
Q

How do you write a single line if statement?

A

puts “It’s true!” if true

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

How do you write a single line unless statement?

A

puts ‘Hello’ unless false

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

What is a ternary conditional expression?

A

A if/else statement is a ternary expression beacuse it takes three arguments:

  • A boolean
  • a expression to evaluate if the boolean is true
  • a expression to evaluate if the boolean is false

boolean ? Do this if true: Do this if false

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

What is a case statement?

A

A case statement is a if/else statement that is used when there are a lot of conditions to check.

case language
  when "JS" then put "Websites!"
  when "Python" then puts "Science!"
  when "Ruby" then puts "Web apps!"
  else puts "I don't know!"
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a conditional assignment?

A

A conditional assignment assigns a variable to a name if the name is nil

favorite_animal = ‘cat’
favorite_animal | |= ‘dog’
print favorite_animal => cat

favorite_animal = nil
favorite_animal | |= ‘dog’
print favorite_animal => ‘dog’

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

What is a implicit return?

A

It means that ruby will return a value even though you did not require it.

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

What is a short-circuit evaluation?

A

It means in a conditional statement with two conditions the second condition is evaluated only when the first condition is not enough to determine the value of expression

false && true

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

What is the concatenation operator?

A

It is «
and used to push in a element to the end of an array or a string.

[1, 2, 3] &laquo_space;4 => [1, 2, 3, 4]
‘Faraz ‘ &laquo_space;‘Naeem’ => ‘Faraz Naeem’

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

What is string interpolation?

A

{ x } its when you add a value to a string, no need to convert it.

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

What is refactoring?

A

Refactoring means that one should make the code simpler and more readable whitout changing its properties or function

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