This file contains hidden or 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
# exercise is a hash | |
exercise = { name: 'jog', category: 'cardio', duration: 10 } | |
exercise.[](:name) # .[]() is a method we can call on only hashes | |
# exercise is an Exercise object | |
exercise = Exercise.new(exercise) | |
# exercise[:name] CAN'T DO THIS! exercise is not a hash anymore, so we can't call hash methods on it | |
# instead, we need to use the attr_reader methods to get attributes of the exercise | |
exercise.name # .name is a method we can call only on Exercise objects |
This file contains hidden or 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
############################################################## | |
#############################CARDS############################ | |
############################################################## | |
class Card | |
def initialize(rank = nil, suit = nil) | |
if suit.nil? | |
@suit = ['♠', '♣', '♥', '♦'].sample | |
else | |
@suit = suit | |
end |
This file contains hidden or 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
1. SELECT movies.title, movies.rating FROM movies ORDER BY movies.rating LIMIT 50; | |
2. SELECT movies.title, movies.rating FROM movies WHERE movies.rating is NULL; | |
3. SELECT movies.title FROM movies WHERE movies.synopsis LIKE '%thrilling%’; | |
4. SELECT movies.title, movies.year, movies.rating | |
FROM movies JOIN genres ON genres.id = movies.genre_id WHERE movies.year BETWEEN 1980 AND 1989 AND genres.name = 'Science Fiction & Fantasy' | |
ORDER BY rating DESC; |
This file contains hidden or 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
scores = [75, 100, 85, 65, 84, 87, 95] | |
def avg(array) | |
total = 0 | |
array.each do |grade| | |
total += grade | |
end | |
avg = total / array.length | |
avg | |
end |
This file contains hidden or 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
favorite_movies = [ | |
{ title: 'The Big Lebowski', year_released: 1998, director: 'Joel Coen', imdb_rating: 8.2 }, | |
{ title: 'The Shining', year_released: 1980, director: 'Stanley Kubrick', imdb_rating: 8.5 }, | |
{ title: 'Troll 2', year_released: 1990, directory: 'Claudio Fragasso', imdb_rating: 2.5 } | |
] | |
favorite_movies.each do |movies| | |
puts "#{movies[:year_released]}: #{movies[:title]}" | |
end |
This file contains hidden or 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 average(grades) | |
grades.map! {|num| num.to_i} | |
grades.inject(0) {|sum, n| sum += n} / grades.size | |
end | |
puts 'Enter grades (one per line, type "done" on a new line when finished):' | |
grades = Array.new | |
grade = gets.chomp | |
while grade.downcase != "done" | |
grades << grade |
This file contains hidden or 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
➜ ~ cat ~/.zshrc | |
# Path to your oh-my-zsh installation. | |
export ZSH=$HOME/.oh-my-zsh | |
# Set name of the theme to load. | |
# Look in ~/.oh-my-zsh/themes/ | |
# Optionally, if you set this to "random", it'll load a random theme each | |
# time that oh-my-zsh is loaded. | |
ZSH_THEME="robbyrussell" |