This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DEEFINE AN ARRAY | |
empty_array = [] # an empty array | |
beatles = ["john", "paul", "ben"] # an array of 3 elements | |
# GET ELEMENT BY ITS INDEX | |
beatles[0] # => "john" | |
beatles[1] # => "paul" | |
beatles[2] # => "ben" | |
# MODIFY AN ELEMENT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write test | |
# code method that takes sentence as parameter | |
# sentence needs to be broken down into words | |
# then into first letters of each word | |
# needs to return a string which is the acronym | |
def acronym(sentence) | |
string = "" | |
sentence.split(" ").each do |word| | |
string += word[0].upcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ONE LINE SYNTAX | |
{ |i| i * 2} | |
# MULTI-LINE SYNTAX | |
do |i| | |
i * 2 | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# def acronymize(sentence) | |
# string = "" | |
# sentence.split(" ").each do |word| | |
# string += word[0].upcase | |
# end | |
# return string | |
# end | |
# redo using map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# def acronymize(sentence) | |
# string = "" | |
# sentence.split(" ").each do |word| | |
# string += word[0].upcase | |
# end | |
# return string | |
# end | |
# redo using map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
def initialize(color) | |
@color = color | |
@engine_started = false | |
end | |
# allow you to read instance variable | |
def color | |
return @color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Citizen | |
def initialize(first_name, last_name, age) | |
@first_name = first_name | |
@last_name = last_name | |
@age = age | |
end | |
def can_vote? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List all customers (name + email), ordered alphabetically (no extra information) | |
# Should yield 59 results | |
SELECT first_name, last_name, email | |
FROM customers | |
ORDER BY last_name asc; | |
# List tracks (Name + Composer) of the Classical playlist | |
# Should yield 75 results | |
SELECT tracks.name, tracks.composer | |
FROM playlist_tracks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateDoctors < ActiveRecord::Migration[5.1] | |
def change | |
create_table :doctors do |t| | |
t.string :first_name | |
t.string :last_name | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Q1 - What's a relational database? | |
a set of tables linked to each other thanks to a system of primary / foreign keys | |
# Q2 - What are the different "table relationships" you know? | |
1:n, 1 to many | |
n:n, many to many | |
1:1, one to one | |
# Q3 - Consider this e-library service. An author, defined by | |
# his name have several books. | |
# A book, defined by its title and publishing year, |
OlderNewer