all Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what is the ruby equivalent of console.log

A

puts

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

how do you comment out in Ruby

A

#

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

do you run Ruby in the browser

A

no

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

how do you run ruby application

A

ruby filename.rb

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

what is the difference between puts and print

A

puts adds a line break and print does not

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

to log an array what do you use

A

P

P[1,2,3]

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

what do you use to log complex data like nested arrays and hashes

A

PP “pretty printing’

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

abbreviation for “Interactive Ruby”

A

irb

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

what does irb do

A

runs Ruby REPL in the terminal similar to browser console

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

what does REPL stand for

A

READ
EVALUATE
Print
Loop

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

what does irb return

A

2 lines
output of code
return value

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

what do you input in irb

A

code you want the output and return value for

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

not all methods have a return value

A

false

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

nil means

A

no value (like null)

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

what is snake case

A

how you write in Ruby using a _ between words instead of camel case

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

how do you exit irb

A

ctrl + d

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

what are the 3 parts of an error message

A
  1. location of error (where)
  2. description (why)
  3. type of error (who)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

4 common types of errors

A
  1. name errors
  2. syntax error
  3. type error
  4. division error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

8 common data types in Ruby

A

strings
methods
numbers
nil
boolean
symbols
arrays
hashes

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

what are strings

A

words

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

how to interpolation in Ruby

A

double quotes “ “

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

what are methods

A

like functions that get called on an instance or class

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

what is an instance

A

one unique object

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

What do you put at the beginning of instance methods

A

#

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

what do you put at the beginning of class methods

A

Self

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

what are the 2 number types

A

integers- whole numbers (7)
floats- decimal numbers (7.2)

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

how do you convert data types to integers

A

_i

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

how do you convert data types to floats

A

_f

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

what does nil represent

A

the absence of value

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

can you assign nil as a value

A

yes

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

what are the types of falsey values

A

nil and false

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

what do symbols represent

A

a piece of data

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

how do you assign a symbol

A

:symbol_name

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

how to create array

A

array_name.new

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

what are hashes

A

same as objects

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

syntax for making methods

A

def method_name
#code
end

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

you must use paratheses

A

false

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

what is the return value of a method

A

the last line of code before end

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

what is scope

A

areas in a program where certain data is available to the programer

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

local varaible created inside a method are unavailable outside the method

A

true

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

local varaible created outside a method are unavailable inside the method

A

true

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

how do you pass varaible outside of method

A

as an arguement

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

4 variable types

A

local - start with lower case letter
global- start with $
instance - start with @
class - start with @@

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

where does global give access

A

to everywhere in code

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

you should use global often

A

false

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

what is pry

A

Ruby REPL with added functionality from irb

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

what is binding.pry similar to in JS

A

debugger

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

what does binding.pry add to code

A

a breakpoint in code to pause execution to check variables, methods and other context

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

what must you add to the top of application to use pry

A

require ‘pry’

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

how do you leave pry console

A

exit

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

what is the else if syntax in Ruby

A

elsif

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

syntax for unless

A

unless condition
if condition is false run the code here
end

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

what is statement modifier

A

write conditions at the end of a line

this_year = 2025
puts “Hey, its 2026” if this_year == 2026

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

what does case statements fo

A

run multiple conditions against one value

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

syntax for case statements

A

case condition
when “value”
“do this”
when “other value”

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

syntax for case statements

A

case condition
when “value”
“do this”
when “other value”
“do this”
else
“do this if no value matches condition”
end

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

what does while loops allow us to do

A

run same line of code multiple times

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

while syntax

A

i = 0
while i<5
puts “count”
count += 1
end

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

until loop do

A

will run until a condition is met

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

until loop syntax

A

count = 0
until counter == 10
puts “count”
counter += 1
end

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

time loops are called on what

A

a number

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

syntax for time loops

A

10.times do |i|
puts “loop”
puts “i is: #{i}”
end

(each loop updates i )

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

what does each loop get used on

A

objects and array

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

each loop syntax

A

(1.. 20).each do |num|
puts num
end

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

what do arrays do

A

store list of data in a specific order

66
Q

CRUD stand for

A

Create, Read, Update, Delete

67
Q

what ruby methed gets the first element of array

A

array.first

68
Q

what ruby method gets the last element of array

A

array.last

69
Q

what ruby method gets the number of elements of array

A

array.length and array.size

70
Q

what ruby method gets the range of elements of array

A

array[0..1]

71
Q

what is the difference between 2 dots and 3 dots in the array bracket range

A

2 dots gives all numbers including first and last
3 dots give all numbers except the last

72
Q

what ruby method gets access to multiple elemets of array

A

array.slice(0,2)

73
Q

what ruby method adds an element to the end of array

A

array.push

74
Q

what ruby method adds an element to the frony of array

A

array.unshift (new) and array «< new element

75
Q

what is shovel method

A

«< that adds to an array
array «< new element

76
Q

what ruby method adds two arrays together and changes the first array

A

array1.concat(array2)

this changes array 1 to include all of the elements

77
Q

what ruby method adds two arrays together and changes doesnt change the first array

A

array1 +array2

78
Q

what ruby method removes the last element

A

array.pop

79
Q

what ruby method removes the first element

A

array.shift

80
Q

what ruby method finds if an element is in an array

A

array.include?(element)

81
Q

what ruby method reverse all elements and doesnt change original array

A

array.reverse

82
Q

what ruby method reverse all elements and does change original array

A

array.reverse!

83
Q

what rby method adds every element together

A

array.sum

84
Q

what ruby method returns the unique elements

A

array.uniq

85
Q

how to create a hash

A

{key1: “value 1” , key2: “value 2”}

86
Q

how to access key within a hash

A

bracket notation [:key1]

87
Q

how do you associate a new value to a key

A

bracket notation hash_name[:key1] = “new value”

88
Q

you can use dot notation with hash

A

false

89
Q

hash method that delete a key and value pair

A

hash.delete(:key)

90
Q

hash method that returns all keys

A

hash.keys

91
Q

hash method that returns all values

A

hash.values

92
Q

has method that determines if hash is empty

A

hash.empty

93
Q

hash method to join 2 together

A

hash1.merge(hash2)

94
Q

what is enumberables

A

iterating over every piece of data

95
Q

iterate every element of an array and return a new array by transforming the values to new values

A

.map

96
Q

syntax for .mao

A

new_array = array.map do |block parameter|
block parameter. method to change each element
end

97
Q

what is block parameter in .map

A

represents each element in array

98
Q

what is the block

A

chunk of code between do and end keywords

99
Q

what are pipes ||

A

argument that is being passed into the block

100
Q

how do you map using the index

A

.map.with_index

101
Q

what do you use to enumerate hashes

A

.each

102
Q

what do you use .each for it

A

want to access each element of array but don’t care about returning a new array

103
Q

what do you use .map / .collect to do

A

want to access every element in an array, calculate a new value and return a new array with the same length as original array

104
Q

what do you use filter/select/find_all to do

A

want to access every element check if it matches some criteria and return a new array of all the values that match

105
Q

what do you use find/detect for

A

want to access every element of array, check if it matches some criteria and return first element that matches only

106
Q

what do you use sort for

A

retunr a new array where all the elements have been sorted by some condition

107
Q

what is OOP

A

object orientation program
type of programming based on the concept of object which contain data in the form of firlds and code in the form of procedures (methods)

108
Q

what is procedural programming

A

programs build in the sequential order and call methods you want shared behaviors between pages in application

109
Q

methods

A

behaviors that an object performs upon its internal data and even upon other code objects

110
Q

what is class

A

blueprint that defines how to build an object

111
Q

what does class contain

A

inctructions for creating new objects and has the ability to create those objects

112
Q

syntax for class

A

def Class
#code about class
end

113
Q

how do you add instance to class

A

instance_name = Class.new

114
Q

what is instantiate

A

bringing a new object to life

115
Q

different instances of a class are different object

A

true

116
Q

what is ruby object notation

A

default way that ruby communicates to you that you are dealing with object or instance of particular class

117
Q

instance dot notation

A

syntax for sending objects messages asking them to perform an operation of task

118
Q

you should put all class in the same file

A

false put them each in their own file with the class name as the file name

119
Q

where do you put a method if you want it to be available to all the instances in the class

A

in the class code block
def class
def method
method code
end
end

120
Q

you can’t call the method in class on its own

A

correct

121
Q

what are local varaibles

A

only acces in a specific local environment

122
Q

you can access local variables in other methods

A

false

123
Q

what are instance variable

A

variable that is accessible in any instance method in a particular instance of class

124
Q

what does instance variable describe

A

attributes and properties of the instance such as name

125
Q

what is setter methods

A

set attributes on the instances of our classes

126
Q

what is getter methods

A

will return the value of the instance variable

127
Q

what does macro return

A

more ruby code instead of a ruby data type

128
Q

what is metaprogramming

A

writing og programs that operate other programs

129
Q

what are the benefits of metaprogramming

A

automate repetive task
concise and descriptive

130
Q

cons of metaprogramming

A

very hard to follow code that can obsures what is actually happening

131
Q

what does attr_reader create

A

getter method

132
Q

what does attr_writer create

A

setter method

133
Q

when do you use a attr_accessor

A

when you need both a getter and setter function

134
Q

macros are usually bad to use

A

false

135
Q

initialize method is called automatically when .new is used

A

true

136
Q

what is program’s design

A

manner in which you the programmer, organize and array the code

137
Q

principals of object oriented design

A

Single responsibly principal
dont repeat yourself (DRY)
Line limits (methods 5 lines, classes 100)

138
Q

what is domain modeling

A

representation of real-world concepts in software

139
Q

what is self

A

special variable that points to the object that “owns’ the current executing order

140
Q

what is self used for

A

decide which execution context to use at any point in the program

141
Q

objects are aware of themselves and can use self

A

true

142
Q

self keyword refers to what

A

the instance or object that the method is being called on

143
Q

what is monkey patching

A

practice of adding methods to or altering ruby built in classes

144
Q

its okay to use monkey patching in real applications

A

false

145
Q

explicit receiver syntax

A

self.method where self is receiving the method

146
Q

implicit receiver syntax

A

omits the self keyword when calling method (just the method is written)

147
Q

you can’t use implicit receiver with setter functions

A

true

148
Q

what are class methods

A

methods called on the class instead of instances

149
Q

class variable scope

A

class scope- accessible to the entire class

150
Q

what is an example of using a class method

A

getting the count of all the instances in a class

151
Q

syntax for class method

A

class Class_name
@@element_count = 0
def self.count
@@album_count
end
end

152
Q

difference in class constants and class variables

A

constants store data that doesn’t change and defines with all capitalize letters

153
Q

syntax for accessing class constant outside of scope

A

Class : : CONSTANT

154
Q

what are public methods

A

can call them from outside the scope of class declaration like on instance or the class itselfg

155
Q

how do you call public methods

A

explicit receiver

156
Q

who are the receiver of private methods

A

self

157
Q

why use private methods

A

encapsulate functionality in a class
show that the method is depended on by other methods in your program

158
Q

how do your create private method

A

add private above the methods that are private methods

159
Q

steps to define custom error

A
  1. define the custom error class
  2. raise custom error
160
Q

what is rescuing

A

rescues program when you get an error and allows program to continue to run

161
Q

steps to handle custom error

A
  1. write custom message
  2. implement the rescue