Skip to content

Instantly share code, notes, and snippets.

View ashleytbasinger's full-sized avatar

Ashley Basinger ashleytbasinger

View GitHub Profile
@ashleytbasinger
ashleytbasinger / game.rb
Created August 20, 2013 01:53
guess the number game for ruby
number = rand(0...100)
puts "Let's play a game!"
print "Guess a number between 0 and 100:"
loop do
guess = gets.chomp
if !/^\d+$/.match(guess)
puts 'Invalid guess, try again...'
print "guess again: "
@ashleytbasinger
ashleytbasinger / hangman.rb
Last active December 21, 2015 15:59
ruby hangman with a fruit theme. lame, i know, but i was grocery shopping simultaneously.
#!/usr/bin/env ruby
require 'pry'
fruits =["pineapple", "kiwi" , "peach" , "pear" , "guava" , "strawberry" , "banana" , "lemon" , "watermelon"]
word = fruits.sample
guesses = 8
hidden = "_" * word.length
@ashleytbasinger
ashleytbasinger / card_constructor.rb
Created August 26, 2013 15:49
Card Constructor
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
@rank = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A'].sample
puts "Create a new card: #{@rank} of #{@suit}"
end
@ashleytbasinger
ashleytbasinger / circle.rb
Created August 27, 2013 13:04
ruby circle
class Circle
# attr_accessor :radius
def initialize(radius)
@radius = radius.to_i
end
def diameter
@diameter = @radius * 2
salutations = [
'Mr.',
'Mrs.',
'Mr.',
'Dr.',
'Ms.'
]
first_names = [
'John',
@ashleytbasinger
ashleytbasinger / tax_man.rb
Created August 31, 2013 19:21
tax man morning kata
require 'benchmark'
tax_records = [
{
first_name: 'Johnny',
last_name: 'Smith',
annual_income: 120000,
tax_paid: 28000
},
{
@ashleytbasinger
ashleytbasinger / mortgage_calculator.rb
Created September 3, 2013 21:32
mortgage calculator
class HomePurchaseOption
attr_reader :address, :property_value, :selling_price, :down_payment
def initialize(attributes)
@address = attributes[:address]
@property_value = attributes[:property_value]
@selling_price = attributes[:selling_price]
@down_payment = attributes[:down_payment]
end
@ashleytbasinger
ashleytbasinger / inheritance.rb
Created September 4, 2013 02:06
inheritance exercise
class Animal
def initialize(name)
@name = name
end
def eat(food)
puts "#{@name} the #{self.class} eats #{food}."
end
def emote
@ashleytbasinger
ashleytbasinger / anagram_generator.rb
Created September 6, 2013 00:29
anagram generator for ruby
#anagram generator
#so help me I will figure this out!
class String
def anagram
self.split(//).permutation.map { |a| a.join}
end
end
input = gets.chomp
@ashleytbasinger
ashleytbasinger / array_assignment.rb
Created September 6, 2013 18:19
TDD array assignment code partner project with Kyle
#require 'Math'
class ArrayStatistic
def initialize(array)
@array = array
end
def largest
@array.sort[-1]
end