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
require 'csv' | |
require 'sqlite3' | |
class PoliticianDB | |
@@politicians_stats =[] | |
def self.setup | |
system('rm politicians.db') | |
$db = SQLite3::Database.new "politicians.db" |
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
require 'csv' | |
class Recipe | |
attr_reader :id, :name, :description, :ingredients, :directions | |
def initialize(data={}) | |
@id = data[:id] | |
@name = data[:name] | |
@description = data[:description] |
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 Car | |
# @@WHEELS = 4 | |
# def initialize(args) | |
# @color = args[:color] | |
# @wheels = @@WHEELS | |
# end | |
# def drive | |
# @status = :driving | |
# end | |
# def brake |
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 Car | |
@@WHEELS = 4 | |
def initialize(args) | |
@color = args[:color] | |
@wheels = @@WHEELS | |
end | |
def drive | |
@status = :driving | |
end | |
def brake |
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 Student | |
attr_accessor :scores, :first_name | |
def initialize(args) #Use named arguments! | |
#your code here | |
end | |
end | |
## ADD YOUR CODE HERE and IN THE CLASS ABOVE |
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 Company | |
attr_accessor :company_name | |
attr_reader :employees | |
def initialize(name) | |
@company_name = name | |
@employees = [] | |
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
class BoggleBoard | |
LETTERS = [["A", "A", "E", "E", "G", "N"], | |
["E", "L", "R", "T", "T", "Y"], | |
["A", "O", "O", "T", "T", "W"], | |
["A", "B", "B", "J", "O", "O"], | |
["E", "H", "R", "T", "V", "W"], | |
["C", "I", "M", "O", "T", "U"], | |
["D", "I", "S", "T", "T", "Y"], | |
["E", "I", "O", "S", "S", "T"], | |
["D", "E", "L", "R", "V", "Y"], |
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 fib_iterative(fibonacci_index) | |
fibonacci_numbers = [0, 1] | |
if fibonacci_index > 1 | |
fibonacci_index.times do | |
fibonacci_numbers << (fibonacci_numbers[-1] + fibonacci_numbers[-2]) | |
end | |
end | |
puts fibonacci_numbers[fibonacci_index] | |
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
# Determine whether a string contains a Social Security number. | |
def has_ssn?(string) | |
end | |
puts "has_ssn? returns true if it has what looks like a SSN" | |
puts has_ssn?("please don't share this: 234-60-1422") == true | |
puts "has_ssn? returns false if it doesn't have a SSN" | |
puts has_ssn?("please confirm your identity: XXX-XX-1422") == false |
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 shuffle(array) | |
array_copy = array.dup | |
sorted_array = [] | |
rand_index_num = rand(array.length) | |
array.select! do |element| | |
sorted_array << array_copy[rand_index_num] | |
array_copy.delete_at(rand_index_num) | |
rand_index_num = rand(array_copy.length) | |
end |
NewerOlder