Introduction Flashcards

1
Q

single line comment

A

comment

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

single line comment

A

comment

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

multi-line comment

A
=begin
this is 
a 
multi line
comment 
=end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Boolean

A

true or false

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

string

A

“just text”

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

print

A

prints a value in the console

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

puts

A

prints a value but adds a line break

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

methods

A

a “skill” or feature of an objec

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

.length

A

shows the length of characters in a string

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

.reverse

A

reverses a string

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

.upcase

A

capitalises an entire string

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

.downcase

A

converts a string to all lowercase

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

gets

A

retrieves user input

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

.chomp

A

removes a blank line

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

{variable}

A

retrieves variable data (user input) and inserts in a string

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

if

A

evaluates something to true or false

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

elsif

A

to insert another evaluations after an “if”

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

else

A

evaluates everything else if the first “if” or “elsif” are false

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

comparator

A

a sign that compares to values such as
== “is equal to”
< is less than

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

less than

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

>

A

greater than

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

<=

A

less than or equal to

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

> =

A

greater than or equal to

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

!=

A

not equal to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
==
equal to
26
&&
and
27
||
or
28
!
not. reverses a true to false object to be the opposite
29
unless
an unless function, another version of "if" runs a function unless the following is true
30
.gsub
substitutes a letter in a string ie user_input.gsub (/s/, "th") the string "th" is what replaces every s
31
end
ends a if, else function
32
multi-line comment
``` =begin this is a multi line comment =end ```
33
Boolean
true or false
34
string
"just text"
35
print
prints a value in the console
36
puts
prints a value but adds a line break
37
methods
a "skill" or feature of an objec
38
.length
shows the length of characters in a string
39
.reverse
reverses a string
40
.upcase
capitalises an entire string
41
.downcase
converts a string to all lowercase
42
gets
retrieves user input
43
.chomp
removes a blank line
44
#{variable}
String interpolation. retrieves variable data (user input) and inserts in a string
45
if
evaluates something to true or false
46
elsif
to insert another evaluations after an "if"
47
else
evaluates everything else if the first "if" or "elsif" are false
48
comparator
a sign that compares to values such as == "is equal to" < is less than
49
less than
50
>
greater than
51
<=
less than or equal to
52
>=
greater than or equal to
53
!=
not equal to
54
==
equal to
55
&&
and
56
||
or
57
!
not. reverses a true to false object to be the opposite
58
unless
an unless function. an action runs unless a condition is true
59
.gsub
substitutes a letter in a string ie user_input.gsub (/s/, "th") the string "th" is what replaces every s
60
end
ends a if, else function
61
one-line If statement
an if statement can be written without and "end" if on one line syntax expression if boolean ex. puts "hello" if true -> hello
62
one-line unless statment
no need for end i.e. puts "hello" unless 2*3 == 5 -> hello
63
ternary expression
a substitute for an if else statement. it takes three arguments: a boolean, an expression to evaluate if the boolean is true, and an expression to evaluate if the boolean is false. syntax boolean ? Do this if true: Do this if false i.e. puts 3 < 4 ? "3 is less than 4!" : "3 is not less than 4."
64
| | =
conditional assignment operator. assigns a real value to a variable only when its current value is false of nil. Otherwise ruby keeps its original value i.e. boyfriend = nil boyfriend ||= "Jimmy Jr." boyfriend ||= "Josh" ``` puts boyfriend # => "Jimmy Jr." ```
65
short circuit evuation
for boolean operators && or ||, ruby will only evaluate to the point it is sure whether the statement is true or false.
66
.upto
iterates over values in a specific range upwards ``` i.e. "B".upto("F") { |letter| print letter, " " } # => B C D E F ```
67
.downto
iterates over values in a specific range downwards i.e 5.downto(0) { |num| print num, " " } # => 5 4 3 2 1 0
68
.respond_to?
takes a symbol representing a method name and returns true if that method can be called on the object and false otherwise. ``` puts "A".respond_to?(:push) # => false # Here, the following Ruby code will return false since .push can’t be called on a String object. ``` ``` puts "A".respond_to?(:next) # => true # Here, however, the following Ruby code will return true since .next can be called on a String object. Calling .next on the letter “A” would return the letter “”. ```
69
<
concatenation operator. an alternative to push. can be used to add an element to the end of an array or a string array = [1, 2, 3] array << 4 print array #Output => [1, 2, 3, 4] ``` puts "Hello," << " welcome to Codecademy." #Output => Hello, welcome to Codecademy. ```