Intro Flashcards
Familiarize yourself with intro level elements of Ruby
What provides ordered, integer-indexed collections of any object?
An Array
How should text be formatted in Classes?
CamelCase
How should text be formatted in methods, arguments and variables?
in_snake_case
How should text be formatted in constants?
IN_SNAKED_UPPERCASE
How is a ternary operator structured?
puts Boolean ? “expression if true” : “expression if false”
What is a shortcut for creating an array of strings?
array_name = %w{“string”, “string”, “string”}
What is a shortcut for creating hashes?
hash_name = {key: ‘value’, key: ‘value’}
How would you use the .each block to access data in a hash?
hash_name.each { | key, name | puts “#{name} => #{value}”}
What does this produce?
a = %w( ant bee cat dog fish)
a.each { |animal| puts animal}
and bee cat dog fish
What are instance variable names led with?
They are lead with the @symbol
The controller passes off heavy code to what?
The model
What are the 4 major classes and objects in Ruby
Arrays, Hashes, Objects and Methods
What is the operator called?
The spaceship operator
Where does Rails look to find the current layout?
Rails first looks for a file in the app/views/layouts with the same base name as the controller
What does the following method do:
redirect_to
Tells the browser to send a new request for a different URL
What are the five types of variables in Ruby?
Local, Instance, Class, Constants and Global
What is the blueprint from which individual objects are created?
A class
What does IRb stand for?
Interactive Ruby
What is IRb?
A shell for experimentation in which you can immediately view expression results, line by line.
What is an identifier?
Identifiers are names of variables, constants, and methods and are case sensitive.
What are variables?
They are memory locations which holds any data to be used by any program.
What is a Global variable?
A variable that is accessible in every scope
What is a Class variable?
A variable defined in a class of which a single copy exists, regardless of how many instances of the class exist
What is the scope of a Local variable?
The scope of a local variable ranges from class, module, def, or within a { } or ‘do/end’ block
What is an Instance variable?
A variable defined in a class and only affect the object that contains it.
What methods pints text to the screen? What are the differences?
Puts & Prints. Puts creates a new line where prints stays on the same line.
What is scope?
The determining factor on where variables can be accessed.
Which character denotes a global variable?
It is denoted by the $ character.
What do reserved words do?
Reserved words that tell the Ruby interpreter what to do.
What is domain modeling
The process of figuring out how the real world is represented in an object oriented program.
Which character denotes an instance variable?
It is denoted by the @ character.
What does a ban method do to a string?
Modifies the receiver in place using the ! character.
What string method tells you the number of characters in a string?
.length
What method will provide a random number between 0-50
rand(50)
What is the name for the position of an item in an array?
An index
What does the unshift method do to an array?
Prepends items to the beginning of an array.
What is the term for a loop that doesn’t end?
An infinite loop
What keyword repeats the current iteration of a loop?
redo
What does the ‘break’ keyword do in a loop?
It ends the loop when a condition is met
What keyword goes to the next item in a loop?
The ‘next’ keyword
What does the ensure block do?
Ensures the code within it gets run regardless of errors.
What does the yield keyword do?
Runs the block
What symbol tells a Ruby method to expect a block?
The & symbol
What will the last statement of a block of code be?
The return value
What are prods & lambdas?
Blocks of code assigned to variables. Can be passed to different methods and the scope can change.
What are modules?
Modules serve as containers for data, classes, methods, or even other modules. Modules are useful for sharing behavior between classes and frequently used for namespacing classes and constants.
What keyword includes a module in a class?
The ‘include’ keyword.
What is the difference between include and extend?
Extend operates on the class, include operates on the instance.
What symbols are used to access methods and constants inside of a module?
The :: symbols
What keyword creates a module?
Module
What method must you define to take advantage of the Comparable module?
The rocket ship method
How would you create a new date?
Date.new(yyyy, mm, dd)
What method must be defined when including the Enumerable module?
the .each method
What is refactoring?
Improving the structure or appearance of our code without changing what it actually does.
What is the conditional assignment operator?
||=
what attribute comes before a method_name?
the ‘def’ attribute
What does CRUD stand for
Create, Read, Update, Destroy
What does MVC stand for
Model-View-Controller