Introduction Flashcards

You may prefer our related Brainscape-certified 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
Q

==

A

equal to

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

&&

A

and

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

||

A

or

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

!

A

not. reverses a true to false object to be the opposite

29
Q

unless

A

an unless function, another version of “if”

runs a function unless the following is true

30
Q

.gsub

A

substitutes a letter in a string ie
user_input.gsub (/s/, “th”)

the string “th” is what replaces every s

31
Q

end

A

ends a if, else function

32
Q

multi-line comment

A
=begin
this is 
a 
multi line
comment 
=end
33
Q

Boolean

A

true or false

34
Q

string

A

“just text”

35
Q

print

A

prints a value in the console

36
Q

puts

A

prints a value but adds a line break

37
Q

methods

A

a “skill” or feature of an objec

38
Q

.length

A

shows the length of characters in a string

39
Q

.reverse

A

reverses a string

40
Q

.upcase

A

capitalises an entire string

41
Q

.downcase

A

converts a string to all lowercase

42
Q

gets

A

retrieves user input

43
Q

.chomp

A

removes a blank line

44
Q

{variable}

A

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

45
Q

if

A

evaluates something to true or false

46
Q

elsif

A

to insert another evaluations after an “if”

47
Q

else

A

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

48
Q

comparator

A

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

49
Q
A

less than

50
Q

>

A

greater than

51
Q

<=

A

less than or equal to

52
Q

> =

A

greater than or equal to

53
Q

!=

A

not equal to

54
Q

==

A

equal to

55
Q

&&

A

and

56
Q

||

A

or

57
Q

!

A

not. reverses a true to false object to be the opposite

58
Q

unless

A

an unless function. an action runs unless a condition is true

59
Q

.gsub

A

substitutes a letter in a string ie
user_input.gsub (/s/, “th”)

the string “th” is what replaces every s

60
Q

end

A

ends a if, else function

61
Q

one-line If statement

A

an if statement can be written without and “end” if on one line

syntax
expression if boolean

ex.

puts “hello” if true

-> hello

62
Q

one-line unless statment

A

no need for end

i.e.
puts “hello” unless 2*3 == 5

-> hello

63
Q

ternary expression

A

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
Q

| =

A

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
Q

short circuit evuation

A

for boolean operators && or ||, ruby will only evaluate to the point it is sure whether the statement is true or false.

66
Q

.upto

A

iterates over values in a specific range upwards

i.e.
"B".upto("F") { |letter| print letter, " " }
# => B C D E F
67
Q

.downto

A

iterates over values in a specific range downwards

i.e
5.downto(0) { |num| print num, “ “ }
# => 5 4 3 2 1 0

68
Q

.respond_to?

A

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
Q

<

A

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 &laquo_space;4
print array
#Output => [1, 2, 3, 4]

puts "Hello," << " welcome to Codecademy."
#Output => Hello, welcome to Codecademy.