Skip to content

Instantly share code, notes, and snippets.

@samstephen
samstephen / app.rb
Last active August 29, 2015 14:23
Shopping Cart
# empower my program with SQLite
require "sqlite3"
# load/create our database for this program
CONNECTION = SQLite3::Database.new("users.db")
# dropping tables to reset the database, can comment out if you'd like to keep history
CONNECTION.execute("DROP TABLE IF EXISTS customers;")
CONNECTION.execute("DROP TABLE IF EXISTS products;")
CONNECTION.execute("DROP TABLE IF EXISTS orders;")
@samstephen
samstephen / app.rb
Last active August 29, 2015 14:22
Warehouse app
# Product Class
class Product
#method that will get/change value of name and shelf_id
attr_accessor :name, :category, :quantity
def initialize(name, quantity)
@name = name
@samstephen
samstephen / app.rb
Created June 5, 2015 18:39
Rock, Paper, Scissors Game
possible_moves = ["rock", "paper", "scissors"]
winner = { "rock" => "scissors", "paper" => "rock", "scissors" => "paper" } # key is winner, value is loser
print "Do you want to play Rock, Paper, Scissors? (yes/no) "
action = gets.chomp.downcase
while action != "no" do
puts "Rock... Paper... Scissors... Chute!"

#Dinner Club Markdown

Making practical and effective use of SRP, the Dinner Club program consists of 3 different files; checksplitter.rb, dinnerclub.rb, and app.rb. CheckSplitter and DinnerClub are two different classes with different functions; carefully laid out to handle a single responsibility amongst themselves and return values to the method. The last file app.rb handles the interaction between the program and user. ##Great, so what does the program do? Programs do things - getting there is a long road but the outcome is sometimes simple to explain. This program, Dinner Club, outputs a few things: the amount each member of Dinner Club has paid, where they went, and who went on the outing. The program looks like this when you run it:

Who is in the dinner club? (Comma-separated)
Sam, James, Amy
Okay, great. Go out to eat?
@samstephen
samstephen / checksplitter.rb
Last active August 29, 2015 14:22
Build a CheckSplitter class
# Build a CheckSplitter class.
# New CheckSplitter objects should have an attribute that stores the total cost of the meal.
# They should have a way to define the tip amount (and a value that's set by default).
# They should be able to define how many people are in the group.
# They should use that information to help determine how much each person owes.
class CheckSplitter
def initialize(meal, quality, group)
@meal = meal