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
class Triplet | |
attr_reader :a, :b, :c | |
def initialize(a, b, c) | |
@a = a | |
@b = b | |
@c = c | |
end | |
def sum |
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
class Cipher | |
VALUES = [('a'..'z').to_a, (0..25).to_a].transpose.to_h | |
attr_reader :key | |
def initialize(key = new_key) | |
@key = key | |
raise_error_conditions | |
end | |
def encode(msg) |
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
class Robot | |
attr_accessor :bearing, :coordinates | |
def orient(direction) | |
if [:north, :east, :south, :west].include? direction | |
self.bearing = direction | |
else | |
raise ArgumentError, "Invalid direction" | |
end | |
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.) Data is stored in tables in a manner where it can retrieved by a unique ID (primary ID) | |
and can be related to data in other tables via foreign key. | |
2.) Structured Query Language is language used to interact with relational databases | |
3.) schema view --> structure of the table (column name, column type, PK, FK, etc...) | |
data view ----> actual data in columns from the table | |
4.) Primary Key |
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
class Board | |
def self.transform(input) | |
output = [] | |
fail ValueError unless valid_game?(input) | |
input.each_with_index do |row, row_index| | |
if row_index == 0 || row_index == (input.size - 1) | |
output << row | |
else | |
output_row = '' |
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.) index, new, create, show, edit, update, delete | |
GET, POST, PATCH/PUT, DELETE | |
GET '/photos', to: photos#index | |
GET '/photos/new, to: photos#new | |
POST '/photos, to: photos#create | |
GET '/photos/:id', to: photos#show | |
GET '/photos/:id/edit', to: photos#edit | |
PATCH '/photos/:id', to: photos#update | |
DELETE '/photos/:id', to: photos#delete | |
"can use as: 'something' to create a custom named route" |
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
class Series | |
attr_reader :series | |
def initialize(series) | |
@series = series | |
end | |
def slices(slice) | |
valid?(slice) | |
last_valid_index = series.length - slice |
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
class Sieve | |
attr_reader :max, :range | |
def initialize(max) | |
@max = max | |
@range = {} | |
(2..max).each { |n| range[n] = 1 } | |
end | |
def primes |
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
class Luhn | |
attr_reader :cd, :luhn, :luhn_sum | |
def initialize(num, create = nil) | |
@luhn = num.to_s.split('').map(&:to_i) | |
@cd = luhn.pop unless create | |
end | |
def addends | |
num = (luhn.size - 1) |
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
class PigLatin | |
def self.translate(phrase) | |
pig = PigLatin.new(phrase).convert | |
end | |
attr_reader :words | |
def initialize(phrase) | |
@words = phrase.split | |
end |
OlderNewer