Control flow Flashcards
1
Q
simple ruby control flow.
A
if condition block elsif condition block else block end
2
Q
test if value is false.
A
unless
3
Q
check if 2 values are equal.
A
==
it should be double equal sign because one equal is used for assignment.
4
Q
check if 2 values are not equal.
A
!=
5
Q
the logical or boolean operators.
A
&&»_space; and
||»_space; or
!»_space; not
6
Q
only returns true when both sides are true.
A
&&
7
Q
returns true if any of the side is true.
A
||
8
Q
turns true value false and vice versa.
A
! ex. !true >> false !(700 / 10 == 70) >> false
9
Q
a method that evaluates to true if find a string inside a string.
A
include
ex.
“I am the guru”.include? “g”
» true
10
Q
what does the method that end with “?” evaluate to?
A
boolean ex. include? blank? empty?
11
Q
How to replace letters in string?
A
gsub
ex.
string_to_change.gsub!(/s/, “th”)
12
Q
give an example of the case conditional statement.
A
case language when "JS" puts "Websites" when "Python" puts "Science" when "Ruby" puts "Web applications" else puts "I don't know" end