Skip to content

Instantly share code, notes, and snippets.

View barangerbenjamin's full-sized avatar

Baranger Benjamin barangerbenjamin

View GitHub Profile
# 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
# 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
# ONE LINE SYNTAX
{ |i| i * 2}
# MULTI-LINE SYNTAX
do |i|
i * 2
end
# def acronymize(sentence)
# string = ""
# sentence.split(" ").each do |word|
# string += word[0].upcase
# end
# return string
# end
# redo using map
# def acronymize(sentence)
# string = ""
# sentence.split(" ").each do |word|
# string += word[0].upcase
# end
# return string
# end
# redo using map
class Car
def initialize(color)
@color = color
@engine_started = false
end
# allow you to read instance variable
def color
return @color
class Citizen
def initialize(first_name, last_name, age)
@first_name = first_name
@last_name = last_name
@age = age
end
def can_vote?
# 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
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
# 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,