Skip to content

Instantly share code, notes, and snippets.

@hchood
hchood / ruby_fund_4_characters.rb
Created November 21, 2013 16:10
Ruby Fundamentals IV: Ruby Data Structures Assignment (Game of Thrones characters)
# Ruby Fundamentals IV: Ruby Data Structures Assignment
characters = {
"Tyrion Lannister" => "House Lannister",
"Jon Snow" => "Night's Watch",
"Hodor" => "House Stark",
"Stannis Baratheon" => "House Baratheon",
"Theon Greyjoy" => "House Greyjoy"
}
@hchood
hchood / echo1.rb
Created November 22, 2013 22:24
Alpha checkpoint: Echo (Phase 1)
# Alpha: Echo checkpoint (Phase 1)
def playback(input)
"You said: #{input}"
end
puts "What do you want to say?"
input = gets.chomp
puts playback(input)
@hchood
hchood / echo2.rb
Last active December 29, 2015 03:29
Alpha checkpoint: Echo (Phase 2)
# Alpha: Echo checkpoint (Phase 2)
def playback(input)
if input == "Nothing!"
"Ok, fine!"
elsif input == "I have a lot to say"
"I don't have time for that right now!"
else
"You said: #{input}"
end
@hchood
hchood / echo3.rb
Last active December 29, 2015 04:58
Alpha checkpoint: Echo (Phase 3)
# Alpha: Echo checkpoint (Phase 3)
def playback(input)
if input == "Nothing!"
"Ok, fine!"
elsif input == "I have a lot to say"
puts "Ok, let's hear it!"
multiline_output_from(gets_lines_of_input)
else
"You said: #{input}"
@hchood
hchood / echo4.rb
Last active December 29, 2015 06:39
Alpha checkpoint: Echo (Phase 4)
# Alpha: Echo checkpoint (Phase 4)
# METHODS
def playback(input) # This method is now way too long. Way to make it shorter? Or just move out of method into main program?
if input == "Nothing!"
"Ok, fine!"
elsif input == "I have a lot to say"
puts "Ok, let's hear it!"
multiline_output_from(gets_lines_of_input)
@hchood
hchood / change4.rb
Created November 24, 2013 23:00
Ruby Fundamentals 4: Cashier challenge #4 (worked with Janet)
# Ruby Fundamentals 4: Challenge
require 'csv'
require 'date'
require 'table_print'
# DATA
products = []
CSV.foreach('products.csv', headers: true) do |row|
@hchood
hchood / kata_change_machine.rb
Created November 24, 2013 23:04
Ruby Fundamentals IV: Non-core Change Machine Kata
# Ruby Fundamentals IV: Non-core Change Machine Kata
def is_valid_currency?(amount)
amount.to_s.match(/\A\d+[.]{0,1}\d{0,2}\z/)
end
amount_due = rand(0.0..100.0)
puts "Amount Due: #{sprintf("%.2f", amount_due)}\n\nWhat did customer supply?"
amount_tendered = gets.chomp.to_f
@hchood
hchood / oop_i_1.rb
Created November 26, 2013 02:19
OOP Fundamentals I: Assignment 1
# OOP Fundamentals I: Assignment 1
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
@hchood
hchood / oop_i_2.rb
Created November 26, 2013 02:24
OOP Fundamentals I: Assignment 2
# OOP Fundamentals I: Assignment 2
class Television
def initialize(brand, display_type, width, height)
@brand = brand
@display_type = display_type
@width = width
@height = height
end
@hchood
hchood / oop_i_3.rb
Created November 26, 2013 02:58
OOP Fundamentals I: Assignment 3
# OOP Fundamentals I: Assignment 3
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color