Skip to content

Instantly share code, notes, and snippets.

View harrisonmalone's full-sized avatar

Harrison Malone harrisonmalone

View GitHub Profile
class Vehicle
def initialize(make, model, tank)
@make = make
@model = model
@fuel = 0
@tank = tank
end
def refuel
input = nil
class Allergies
def initialize(num)
@allergy_num = num
@allergy_list = ['eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats']
@exp = @allergy_list.count
@my_allergies = []
get_allergies(num)
end
def list
def word_battle(word_one, word_two)
# we split the words into an array
arr_word_one = word_one.split("")
arr_word_two = word_two.split("")
# we get the letters that are common to each word (using a comparison loop) and push them into an array
common_letters = []
arr_word_one.each do |letterone|
arr_word_two.each do |lettertwo|
if letterone == lettertwo
common_letters << letterone
class Continent
attr_reader :countries, :name
@@continents = 0
@@continent_objects = []
def self.num_of_continents
return @@continents
end
def self.print_num_of_continents
# this is maybe the most important day in ruby fundamentals
animals = %w(Calf Duck Elephant Goat Lamb Lion Mule Dog)
animals[8] = "Puma"
animals.insert(4, "Joey")
p animals
animals.reverse!
p animals
animals[2] = "Foal"
animals.push("Bear")
cocktails = 3
waters = 2
beers = 6
puts "what would you like to order"
order = gets.chomp
if order == "cocktail"
cocktails += 1
elsif order == "water"
# the main difference between `.each` and `.map`
# they both iterate through a block but if you want to store an edited array or hash you need to use map
# if you simply want to display text by using `puts` on the block arguments then `each` is more useful
furniture = [
{"name" => "bed", "color" => "black", "size" => "12", "date_created" => "12/6", "condition" => "New"},
{"name" => "chair", "color" => "brown", "size" => "7", "date_created" => "6/13", "condition" => "Used"},
{"name" => "desk", "color" => "maple", "size" => "9", "date_created" => "2/13", "condition" => "New"}
]
class Hamburger
def initialize(patty, bun, condiments, cheese)
@patty = patty #string
@bun = bun #string
@condiments = condiments #array of strings
@cheese = cheese
@price = 450
end
def get_cheese
class Dog
attr_accessor :location
def initialize(name, age)
@name = name
@age = age
@location = location
@distance = 0
@walks = 0
@walk_data = []
end
5 <= 6
# for the less than or more than and equals to symbol remember that the order is always how it's actually read
# the less than and more than come first and then the equals to comes second in the way you say it