all Flashcards
what is the ruby equivalent of console.log
puts
how do you comment out in Ruby
#
do you run Ruby in the browser
no
how do you run ruby application
ruby filename.rb
what is the difference between puts and print
puts adds a line break and print does not
to log an array what do you use
P
P[1,2,3]
what do you use to log complex data like nested arrays and hashes
PP “pretty printing’
abbreviation for “Interactive Ruby”
irb
what does irb do
runs Ruby REPL in the terminal similar to browser console
what does REPL stand for
READ
EVALUATE
Print
Loop
what does irb return
2 lines
output of code
return value
what do you input in irb
code you want the output and return value for
not all methods have a return value
false
nil means
no value (like null)
what is snake case
how you write in Ruby using a _ between words instead of camel case
how do you exit irb
ctrl + d
what are the 3 parts of an error message
- location of error (where)
- description (why)
- type of error (who)
4 common types of errors
- name errors
- syntax error
- type error
- division error
8 common data types in Ruby
strings
methods
numbers
nil
boolean
symbols
arrays
hashes
what are strings
words
how to interpolation in Ruby
double quotes “ “
what are methods
like functions that get called on an instance or class
what is an instance
one unique object
What do you put at the beginning of instance methods
#
what do you put at the beginning of class methods
Self
what are the 2 number types
integers- whole numbers (7)
floats- decimal numbers (7.2)
how do you convert data types to integers
_i
how do you convert data types to floats
_f
what does nil represent
the absence of value
can you assign nil as a value
yes
what are the types of falsey values
nil and false
what do symbols represent
a piece of data
how do you assign a symbol
:symbol_name
how to create array
array_name.new
what are hashes
same as objects
syntax for making methods
def method_name
#code
end
you must use paratheses
false
what is the return value of a method
the last line of code before end
what is scope
areas in a program where certain data is available to the programer
local varaible created inside a method are unavailable outside the method
true
local varaible created outside a method are unavailable inside the method
true
how do you pass varaible outside of method
as an arguement
4 variable types
local - start with lower case letter
global- start with $
instance - start with @
class - start with @@
where does global give access
to everywhere in code
you should use global often
false
what is pry
Ruby REPL with added functionality from irb
what is binding.pry similar to in JS
debugger
what does binding.pry add to code
a breakpoint in code to pause execution to check variables, methods and other context
what must you add to the top of application to use pry
require ‘pry’
how do you leave pry console
exit
what is the else if syntax in Ruby
elsif
syntax for unless
unless condition
if condition is false run the code here
end
what is statement modifier
write conditions at the end of a line
this_year = 2025
puts “Hey, its 2026” if this_year == 2026
what does case statements fo
run multiple conditions against one value
syntax for case statements
case condition
when “value”
“do this”
when “other value”
syntax for case statements
case condition
when “value”
“do this”
when “other value”
“do this”
else
“do this if no value matches condition”
end
what does while loops allow us to do
run same line of code multiple times
while syntax
i = 0
while i<5
puts “count”
count += 1
end
until loop do
will run until a condition is met
until loop syntax
count = 0
until counter == 10
puts “count”
counter += 1
end
time loops are called on what
a number
syntax for time loops
10.times do |i|
puts “loop”
puts “i is: #{i}”
end
(each loop updates i )
what does each loop get used on
objects and array
each loop syntax
(1.. 20).each do |num|
puts num
end