all Flashcards

(161 cards)

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
what do you put at the beginning of class methods
Self
26
what are the 2 number types
integers- whole numbers (7) floats- decimal numbers (7.2)
27
how do you convert data types to integers
#_i
28
how do you convert data types to floats
#_f
29
what does nil represent
the absence of value
30
can you assign nil as a value
yes
31
what are the types of falsey values
nil and false
32
what do symbols represent
a piece of data
33
how do you assign a symbol
:symbol_name
34
how to create array
array_name.new
35
what are hashes
same as objects
36
syntax for making methods
def method_name #code end
37
you must use paratheses
false
38
what is the return value of a method
the last line of code before end
39
what is scope
areas in a program where certain data is available to the programer
40
local varaible created inside a method are unavailable outside the method
true
41
local varaible created outside a method are unavailable inside the method
true
42
how do you pass varaible outside of method
as an arguement
43
4 variable types
local - start with lower case letter global- start with $ instance - start with @ class - start with @@
44
where does global give access
to everywhere in code
45
you should use global often
false
46
what is pry
Ruby REPL with added functionality from irb
47
what is binding.pry similar to in JS
debugger
48
what does binding.pry add to code
a breakpoint in code to pause execution to check variables, methods and other context
49
what must you add to the top of application to use pry
require 'pry'
50
how do you leave pry console
exit
51
what is the else if syntax in Ruby
elsif
52
syntax for unless
unless condition if condition is false run the code here end
53
what is statement modifier
write conditions at the end of a line this_year = 2025 puts "Hey, its 2026" if this_year == 2026
54
what does case statements fo
run multiple conditions against one value
55
syntax for case statements
case condition when "value" "do this" when "other value"
56
syntax for case statements
case condition when "value" "do this" when "other value" "do this" else "do this if no value matches condition" end
57
what does while loops allow us to do
run same line of code multiple times
58
while syntax
i = 0 while i<5 puts "count" count += 1 end
59
until loop do
will run until a condition is met
60
until loop syntax
count = 0 until counter == 10 puts "count" counter += 1 end
61
time loops are called on what
a number
62
syntax for time loops
10.times do |i| puts "loop" puts "i is: #{i}" end (each loop updates i )
63
what does each loop get used on
objects and array
64
each loop syntax
(1.. 20).each do |num| puts num end
65
what do arrays do
store list of data in a specific order
66
CRUD stand for
Create, Read, Update, Delete
67
what ruby methed gets the first element of array
array.first
68
what ruby method gets the last element of array
array.last
69
what ruby method gets the number of elements of array
array.length and array.size
70
what ruby method gets the range of elements of array
array[0..1]
71
what is the difference between 2 dots and 3 dots in the array bracket range
2 dots gives all numbers including first and last 3 dots give all numbers except the last
72
what ruby method gets access to multiple elemets of array
array.slice(0,2)
73
what ruby method adds an element to the end of array
array.push
74
what ruby method adds an element to the frony of array
array.unshift (new) and array <<< new element
75
what is shovel method
<<< that adds to an array array <<< new element
76
what ruby method adds two arrays together and changes the first array
array1.concat(array2) this changes array 1 to include all of the elements
77
what ruby method adds two arrays together and changes doesnt change the first array
array1 +array2
78
what ruby method removes the last element
array.pop
79
what ruby method removes the first element
array.shift
80
what ruby method finds if an element is in an array
array.include?(element)
81
what ruby method reverse all elements and doesnt change original array
array.reverse
82
what ruby method reverse all elements and does change original array
array.reverse!
83
what rby method adds every element together
array.sum
84
what ruby method returns the unique elements
array.uniq
85
how to create a hash
{key1: "value 1" , key2: "value 2"}
86
how to access key within a hash
bracket notation [:key1]
87
how do you associate a new value to a key
bracket notation hash_name[:key1] = "new value"
88
you can use dot notation with hash
false
89
hash method that delete a key and value pair
hash.delete(:key)
90
hash method that returns all keys
hash.keys
91
hash method that returns all values
hash.values
92
has method that determines if hash is empty
hash.empty
93
hash method to join 2 together
hash1.merge(hash2)
94
what is enumberables
iterating over every piece of data
95
iterate every element of an array and return a new array by transforming the values to new values
.map
96
syntax for .mao
new_array = array.map do |block parameter| block parameter. method to change each element end
97
what is block parameter in .map
represents each element in array
98
what is the block
chunk of code between do and end keywords
99
what are pipes ||
argument that is being passed into the block
100
how do you map using the index
.map.with_index
101
what do you use to enumerate hashes
.each
102
what do you use .each for it
want to access each element of array but don't care about returning a new array
103
what do you use .map / .collect to do
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
what do you use filter/select/find_all to do
want to access every element check if it matches some criteria and return a new array of all the values that match
105
what do you use find/detect for
want to access every element of array, check if it matches some criteria and return first element that matches only
106
what do you use sort for
retunr a new array where all the elements have been sorted by some condition
107
what is OOP
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
what is procedural programming
programs build in the sequential order and call methods you want shared behaviors between pages in application
109
methods
behaviors that an object performs upon its internal data and even upon other code objects
110
what is class
blueprint that defines how to build an object
111
what does class contain
inctructions for creating new objects and has the ability to create those objects
112
syntax for class
def Class #code about class end
113
how do you add instance to class
instance_name = Class.new
114
what is instantiate
bringing a new object to life
115
different instances of a class are different object
true
116
what is ruby object notation
default way that ruby communicates to you that you are dealing with object or instance of particular class
117
instance dot notation
syntax for sending objects messages asking them to perform an operation of task
118
you should put all class in the same file
false put them each in their own file with the class name as the file name
119
where do you put a method if you want it to be available to all the instances in the class
in the class code block def class def method method code end end
120
you can't call the method in class on its own
correct
121
what are local varaibles
only acces in a specific local environment
122
you can access local variables in other methods
false
123
what are instance variable
variable that is accessible in any instance method in a particular instance of class
124
what does instance variable describe
attributes and properties of the instance such as name
125
what is setter methods
set attributes on the instances of our classes
126
what is getter methods
will return the value of the instance variable
127
what does macro return
more ruby code instead of a ruby data type
128
what is metaprogramming
writing og programs that operate other programs
129
what are the benefits of metaprogramming
automate repetive task concise and descriptive
130
cons of metaprogramming
very hard to follow code that can obsures what is actually happening
131
what does attr_reader create
getter method
132
what does attr_writer create
setter method
133
when do you use a attr_accessor
when you need both a getter and setter function
134
macros are usually bad to use
false
135
initialize method is called automatically when .new is used
true
136
what is program's design
manner in which you the programmer, organize and array the code
137
principals of object oriented design
Single responsibly principal dont repeat yourself (DRY) Line limits (methods 5 lines, classes 100)
138
what is domain modeling
representation of real-world concepts in software
139
what is self
special variable that points to the object that "owns' the current executing order
140
what is self used for
decide which execution context to use at any point in the program
141
objects are aware of themselves and can use self
true
142
self keyword refers to what
the instance or object that the method is being called on
143
what is monkey patching
practice of adding methods to or altering ruby built in classes
144
its okay to use monkey patching in real applications
false
145
explicit receiver syntax
self.method where self is receiving the method
146
implicit receiver syntax
omits the self keyword when calling method (just the method is written)
147
you can't use implicit receiver with setter functions
true
148
what are class methods
methods called on the class instead of instances
149
class variable scope
class scope- accessible to the entire class
150
what is an example of using a class method
getting the count of all the instances in a class
151
syntax for class method
class Class_name @@element_count = 0 def self.count @@album_count end end
152
difference in class constants and class variables
constants store data that doesn't change and defines with all capitalize letters
153
syntax for accessing class constant outside of scope
Class : : CONSTANT
154
what are public methods
can call them from outside the scope of class declaration like on instance or the class itselfg
155
how do you call public methods
explicit receiver
156
who are the receiver of private methods
self
157
why use private methods
encapsulate functionality in a class show that the method is depended on by other methods in your program
158
how do your create private method
add private above the methods that are private methods
159
steps to define custom error
1. define the custom error class 2. raise custom error
160
what is rescuing
rescues program when you get an error and allows program to continue to run
161
steps to handle custom error
1. write custom message 2. implement the rescue