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 Vehicle | |
def initialize(make, model, tank) | |
@make = make | |
@model = model | |
@fuel = 0 | |
@tank = tank | |
end | |
def refuel | |
input = nil |
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 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 |
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 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 |
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
# probably the most discussed challenge in the ruby fundamentals | |
# some nice logic required | |
hat_arr = [] | |
counter = 0 | |
100.times do | |
# here we create the hat array with 100 false items | |
hat_arr[counter] = true | |
counter += 1 |
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 Continent | |
attr_reader :countries, :name | |
@@continents = 0 | |
@@continent_objects = [] | |
def self.num_of_continents | |
return @@continents | |
end | |
def self.print_num_of_continents |
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
# 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") |
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
cocktails = 3 | |
waters = 2 | |
beers = 6 | |
puts "what would you like to order" | |
order = gets.chomp | |
if order == "cocktail" | |
cocktails += 1 | |
elsif order == "water" |
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
square = width * 2 | |
puts "what\'s the width of your square" | |
width = gets.chomp.to_i | |
square = width ** 2 | |
p square | |
puts "what\'s the length of the rectangle" | |
length = gets.chomp.to_i | |
puts "what\'s the width of the rectangle" | |
width = gets.chomp.to_i | |
rectangle = length * width |
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
# 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"} | |
] |
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 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 |
OlderNewer