From c5da6d6e01407c217369be8a041d47cefa3a85ba Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 12 Apr 2018 13:56:43 -0500 Subject: [PATCH] ruby model exercises --- The only real coder here/ruby models | 1 + cole_wittrock/readme.txt | 1 - derek_love/OOP/bank.rb | 62 ------ derek_love/OOP/dog/dog.rb | 29 --- derek_love/OOP/dog/mammal.rb | 11 - derek_love/OOP/lion/lion.rb | 35 ---- derek_love/OOP/lion/mammal.rb | 11 - derek_love/OOP/math_dojo.rb | 41 ---- derek_love/OOP/project.rb | 15 -- derek_love/OOP/test.rb | 43 ---- derek_love/OOP/wiz_ninja_samurai/human.rb | 31 --- derek_love/OOP/wiz_ninja_samurai/ninja.rb | 28 --- derek_love/OOP/wiz_ninja_samurai/samurai.rb | 37 ---- derek_love/OOP/wiz_ninja_samurai/wizard.rb | 31 --- derek_love/rubyFun/arrays.rb | 27 --- derek_love/rubyFun/basics.rb | 87 -------- derek_love/rubyFun/enumerable.rb | 12 -- derek_love/rubyFun/guess_number.rb | 10 - derek_love/rubyFun/hashes.rb | 6 - derek_love/rubyFun/names.rb | 10 - derek_love/rubyFun/puzzles.rb | 61 ------ derek_love/rubyFun/range.rb | 7 - dillon_votaw/OOP/animals/dog.rb | 20 -- dillon_votaw/OOP/animals/lion.rb | 28 --- dillon_votaw/OOP/animals/mammal.rb | 9 - dillon_votaw/OOP/bank_account.rb | 75 ------- dillon_votaw/OOP/human.rb | 82 -------- dillon_votaw/OOP/mathdojo.rb | 40 ---- dillon_votaw/OOP/oop_examples.rb | 121 ----------- dillon_votaw/OOP/project.rb | 15 -- dillon_votaw/fundamentals/arrays.rb | 24 --- dillon_votaw/fundamentals/basic_13.rb | 104 ---------- dillon_votaw/fundamentals/guess_the_number.rb | 12 -- dillon_votaw/fundamentals/hajime.rb | 189 ------------------ dillon_votaw/fundamentals/hashes.rb | 8 - .../fundamentals/module_practice/main.rb | 12 -- .../module_practice/my_enumerable.rb | 12 -- .../module_practice/printer_module.rb | 7 - dillon_votaw/fundamentals/names.rb | 18 -- dillon_votaw/fundamentals/range.rb | 8 - dillon_votaw/fundamentals/ruby_puzzles.rb | 64 ------ kyla_stearns/Fundamentals/arrays.rb | 38 ---- kyla_stearns/Fundamentals/basic13.rb | 89 --------- kyla_stearns/Fundamentals/guess.rb | 8 - kyla_stearns/Fundamentals/hashes.rb | 18 -- kyla_stearns/Fundamentals/myEnumerables.rb | 10 - kyla_stearns/Fundamentals/names.rb | 12 -- kyla_stearns/Fundamentals/puzzles.rb | 58 ------ kyla_stearns/Fundamentals/range.rb | 13 -- kyla_stearns/Fundamentals/symbols.rb | 0 shane_fisher/fundamentals/GuessTheNumber.rb | 11 - shane_fisher/fundamentals/basic13.rb | 120 ----------- shane_fisher/fundamentals/names.rb | 14 -- shane_fisher/fundamentals/range.rb | 6 - shane_fisher/fundamentals/rubypuzzles.rb | 97 --------- shane_fisher/oop/Dog/dog.rb | 17 -- shane_fisher/oop/Dog/mammal.rb | 11 - shane_fisher/oop/Human/human.rb | 26 --- shane_fisher/oop/Lion/lion.rb | 29 --- shane_fisher/oop/Lion/mammal.rb | 11 - shane_fisher/oop/MathDojo.rb | 17 -- shane_fisher/oop/Project.rb | 16 -- shane_fisher/oop/WNS/human.rb | 22 -- shane_fisher/oop/WNS/ninja.rb | 19 -- shane_fisher/oop/WNS/samurai.rb | 27 --- shane_fisher/oop/WNS/wizard.rb | 20 -- 66 files changed, 1 insertion(+), 2152 deletions(-) create mode 160000 The only real coder here/ruby models delete mode 100644 cole_wittrock/readme.txt delete mode 100644 derek_love/OOP/bank.rb delete mode 100644 derek_love/OOP/dog/dog.rb delete mode 100644 derek_love/OOP/dog/mammal.rb delete mode 100644 derek_love/OOP/lion/lion.rb delete mode 100644 derek_love/OOP/lion/mammal.rb delete mode 100644 derek_love/OOP/math_dojo.rb delete mode 100644 derek_love/OOP/project.rb delete mode 100644 derek_love/OOP/test.rb delete mode 100644 derek_love/OOP/wiz_ninja_samurai/human.rb delete mode 100644 derek_love/OOP/wiz_ninja_samurai/ninja.rb delete mode 100644 derek_love/OOP/wiz_ninja_samurai/samurai.rb delete mode 100644 derek_love/OOP/wiz_ninja_samurai/wizard.rb delete mode 100644 derek_love/rubyFun/arrays.rb delete mode 100644 derek_love/rubyFun/basics.rb delete mode 100644 derek_love/rubyFun/enumerable.rb delete mode 100644 derek_love/rubyFun/guess_number.rb delete mode 100644 derek_love/rubyFun/hashes.rb delete mode 100644 derek_love/rubyFun/names.rb delete mode 100644 derek_love/rubyFun/puzzles.rb delete mode 100644 derek_love/rubyFun/range.rb delete mode 100644 dillon_votaw/OOP/animals/dog.rb delete mode 100644 dillon_votaw/OOP/animals/lion.rb delete mode 100644 dillon_votaw/OOP/animals/mammal.rb delete mode 100644 dillon_votaw/OOP/bank_account.rb delete mode 100644 dillon_votaw/OOP/human.rb delete mode 100644 dillon_votaw/OOP/mathdojo.rb delete mode 100644 dillon_votaw/OOP/oop_examples.rb delete mode 100644 dillon_votaw/OOP/project.rb delete mode 100644 dillon_votaw/fundamentals/arrays.rb delete mode 100644 dillon_votaw/fundamentals/basic_13.rb delete mode 100644 dillon_votaw/fundamentals/guess_the_number.rb delete mode 100644 dillon_votaw/fundamentals/hajime.rb delete mode 100644 dillon_votaw/fundamentals/hashes.rb delete mode 100644 dillon_votaw/fundamentals/module_practice/main.rb delete mode 100644 dillon_votaw/fundamentals/module_practice/my_enumerable.rb delete mode 100644 dillon_votaw/fundamentals/module_practice/printer_module.rb delete mode 100644 dillon_votaw/fundamentals/names.rb delete mode 100644 dillon_votaw/fundamentals/range.rb delete mode 100644 dillon_votaw/fundamentals/ruby_puzzles.rb delete mode 100644 kyla_stearns/Fundamentals/arrays.rb delete mode 100644 kyla_stearns/Fundamentals/basic13.rb delete mode 100644 kyla_stearns/Fundamentals/guess.rb delete mode 100644 kyla_stearns/Fundamentals/hashes.rb delete mode 100644 kyla_stearns/Fundamentals/myEnumerables.rb delete mode 100644 kyla_stearns/Fundamentals/names.rb delete mode 100644 kyla_stearns/Fundamentals/puzzles.rb delete mode 100644 kyla_stearns/Fundamentals/range.rb delete mode 100644 kyla_stearns/Fundamentals/symbols.rb delete mode 100644 shane_fisher/fundamentals/GuessTheNumber.rb delete mode 100644 shane_fisher/fundamentals/basic13.rb delete mode 100644 shane_fisher/fundamentals/names.rb delete mode 100644 shane_fisher/fundamentals/range.rb delete mode 100644 shane_fisher/fundamentals/rubypuzzles.rb delete mode 100644 shane_fisher/oop/Dog/dog.rb delete mode 100644 shane_fisher/oop/Dog/mammal.rb delete mode 100644 shane_fisher/oop/Human/human.rb delete mode 100644 shane_fisher/oop/Lion/lion.rb delete mode 100644 shane_fisher/oop/Lion/mammal.rb delete mode 100644 shane_fisher/oop/MathDojo.rb delete mode 100644 shane_fisher/oop/Project.rb delete mode 100644 shane_fisher/oop/WNS/human.rb delete mode 100644 shane_fisher/oop/WNS/ninja.rb delete mode 100644 shane_fisher/oop/WNS/samurai.rb delete mode 100644 shane_fisher/oop/WNS/wizard.rb diff --git a/The only real coder here/ruby models b/The only real coder here/ruby models new file mode 160000 index 0000000..6e47406 --- /dev/null +++ b/The only real coder here/ruby models @@ -0,0 +1 @@ +Subproject commit 6e47406a1c21d752666716d5f1ef5abb67aa76da diff --git a/cole_wittrock/readme.txt b/cole_wittrock/readme.txt deleted file mode 100644 index fb6b34d..0000000 --- a/cole_wittrock/readme.txt +++ /dev/null @@ -1 +0,0 @@ -just pushing a file \ No newline at end of file diff --git a/derek_love/OOP/bank.rb b/derek_love/OOP/bank.rb deleted file mode 100644 index 0fa767d..0000000 --- a/derek_love/OOP/bank.rb +++ /dev/null @@ -1,62 +0,0 @@ -class Bank - attr_accessor :checking, :savings - - @@num_of_accts = 0 - @@interest_rate = 0.01 - - def initialize - @checking = 0 - @savings = 0 - - @@num_of_accts += 1 - p ("Accounts Created: #{@@num_of_accts}") - end - - def acct_info - p "Account Number: #{bank_acct}" - p "Account Totals: #{total}" - p "Checking Total: #{checking_acct}" - p "Savings Total: #{savings_acct}" - p "Interest Rate: #{@@interest_rate}" - end - - def checking_acct - return @checking - self - end - - def savings_acct - return @savings - self - end - - def deposit(acct, num) - if acct == 'checking' - @checking += num - elsif acct == 'savings' - @savings += num - end - self - end - - def withdraw(acct, num) - if acct == 'checking' - @checking -= num - checking_acct - elsif acct == 'savings' - @savings -= num - savings_acct - end - self - end - - def total - return @checking + @savings - self - end - - private - def bank_acct - return @account_num = rand(10000..100000) - end -end \ No newline at end of file diff --git a/derek_love/OOP/dog/dog.rb b/derek_love/OOP/dog/dog.rb deleted file mode 100644 index bf5b767..0000000 --- a/derek_love/OOP/dog/dog.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative 'mammal' - -class Dog < Mammal - attr_accessor :health - - def dog_health - display_health - self - end - - def pet - @health += 5 - self - end - - def walk - @health -= 1 - self - end - - def run - @health -= 10 - self - end -end - -doggo = Dog.new - -doggo.walk.walk.walk.run.run.pet.dog_health \ No newline at end of file diff --git a/derek_love/OOP/dog/mammal.rb b/derek_love/OOP/dog/mammal.rb deleted file mode 100644 index 732cb74..0000000 --- a/derek_love/OOP/dog/mammal.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Mammal - attr_accessor :health - - def initialize - @health = 150 - end - - def display_health - p @health - end -end \ No newline at end of file diff --git a/derek_love/OOP/lion/lion.rb b/derek_love/OOP/lion/lion.rb deleted file mode 100644 index 4cb5177..0000000 --- a/derek_love/OOP/lion/lion.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative 'mammal' - -class Lion < Mammal - - attr_accessor :health - - def initialize - @health = 170 - end - - def fly - @health -= 10 - self - end - - def attack_town - @health -= 50 - self - end - - def eat_humans - @health +=20 - self - end - - def lion_health - p "This is a lion #{display_health}" - self - end -end - -crazy = Lion.new - -crazy.attack_town.attack_town.attack_town.eat_humans.eat_humans.fly.fly.lion_health - diff --git a/derek_love/OOP/lion/mammal.rb b/derek_love/OOP/lion/mammal.rb deleted file mode 100644 index ffe8869..0000000 --- a/derek_love/OOP/lion/mammal.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Mammal - attr_accessor :health - - def initialize - @health = 150 - end - - def display_health - @health - end -end \ No newline at end of file diff --git a/derek_love/OOP/math_dojo.rb b/derek_love/OOP/math_dojo.rb deleted file mode 100644 index 9c89627..0000000 --- a/derek_love/OOP/math_dojo.rb +++ /dev/null @@ -1,41 +0,0 @@ -class MathDojo - attr_accessor :result - - def initialize - @result = 0 - end - - def add(*nums) - for i in 0...nums.length - if nums[i].respond_to?(:to_i) == true - @result += nums[i] - - elsif nums[i].respond_to?(:to_a) == true - for x in 0...nums[i].length - @result += nums[i][x] - end - end - end - p @result - self - end - - def subtract(*nums) - for i in 0...nums.length - if nums[i].respond_to?(:to_i) - @result -= nums[i] - - elsif nums[i].respond_to?(:to_a) - for x in 0...nums[i].length - @result -= nums[i][x] - end - end - end - self - p @result - end - -end - -challenge1 = MathDojo.new.add(2).add(2, 5).subtract(3,2) -challenge2 = MathDojo.new.add(1).add([3,5,7,8], [2, 4.3, 1.25]).subtract([2, 3], [1.1, 2.3]) \ No newline at end of file diff --git a/derek_love/OOP/project.rb b/derek_love/OOP/project.rb deleted file mode 100644 index 24b2822..0000000 --- a/derek_love/OOP/project.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Project - attr_accessor :name, :description - def initialize(name, description) - @name = name - @description = description - end - - def elevator_pitch - p "#{@name}, #{@description}" - end -end - -project1 = Project.new('Project', 'new project for Coding Dojo') -project1.elevator_pitch -p project1.name diff --git a/derek_love/OOP/test.rb b/derek_love/OOP/test.rb deleted file mode 100644 index dca8c7d..0000000 --- a/derek_love/OOP/test.rb +++ /dev/null @@ -1,43 +0,0 @@ -class User - attr_accessor :first_name, :last_name - def initialize(f_name, l_name) - @first_name = f_name - @last_name = l_name - end - - def full_name - p "Hello, I am #{@first_name} #{@last_name}" - end - - def self.foo - p "bar" - end -end - -user1 = User.new('Derek', 'Love') -user2 = User.new('Allison', 'Bowers') - -class CodingDojo - @@no_of_branches = 0 - def initialize(id, name, address) - @branch_id = id - @branch_name = name - @branch_address = address - @@no_of_branches += 1 - puts "Created branch #{@@no_of_branches}" - end - def hello - puts "Hello CodingDojo!" - end - def display_all - puts "Branch ID: #{@branch_id}" - puts "Branch Name: #{@branch_name}" - puts "Branch Address: #{@branch_address}" - end - def self.num_of_branches - @@no_of_branches - end -end -seattle = CodingDojo.new(1, "Seattle", "123 Seattle Avenue") -san_jose = CodingDojo.new(2, "San Jose", "456 San Jose Boulevard") -burbank = CodingDojo.new(3, "Burbank", "789 Burbank Street") diff --git a/derek_love/OOP/wiz_ninja_samurai/human.rb b/derek_love/OOP/wiz_ninja_samurai/human.rb deleted file mode 100644 index 7c9b3f5..0000000 --- a/derek_love/OOP/wiz_ninja_samurai/human.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Human - attr_accessor :strength, :intelligence, :stealth, :health - - def initialize - @strength = 3 - @intelligence = 3 - @stealth = 3 - @health = 100 - end - - def display - p "Strength: #{@strength}, Intelligence: #{@intelligence}, Stealth: #{@stealth}, Health: #{@health}" - end - - def attack(enemy) - if enemy.class.ancestors.include? Human - enemy.health -= 20 - else - p "You punched a kitten!" - end - self - end - -end - -# derek = Human.new -# allison = Human.new - -# allison.attack(derek).attack(derek) - -# p derek.health diff --git a/derek_love/OOP/wiz_ninja_samurai/ninja.rb b/derek_love/OOP/wiz_ninja_samurai/ninja.rb deleted file mode 100644 index ca5cde2..0000000 --- a/derek_love/OOP/wiz_ninja_samurai/ninja.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative 'human' - -class Ninja < Human - def initialize - super() - @stealth = 175 - end - - def steal(enemy) - if enemy.class.ancestors.include? Human - enemy.health -= 10 - else - p "You stole from a child!" - end - self - end - - def get_away - @health -= 15 - self - end - - def ninja_display - super.display - self - end -end - diff --git a/derek_love/OOP/wiz_ninja_samurai/samurai.rb b/derek_love/OOP/wiz_ninja_samurai/samurai.rb deleted file mode 100644 index ad1da3d..0000000 --- a/derek_love/OOP/wiz_ninja_samurai/samurai.rb +++ /dev/null @@ -1,37 +0,0 @@ -require_relative 'human' - -class Samurai < Human - attr_accessor :strength, :intelligence, :stealth, :health - - @@num_of_samurai = 0 - - def initialize - super() - @health = 200 - - @@num_of_samurai += 1 - end - - def death_blow(enemy) - if enemy.class.ancestors.include? Human - enemy.health = 0 - else - p "You killed a kitten!!!" - end - end - - def meditate - @health = 200 - end - - def how_many - p "There are #{@@num_of_samurai} samurais" - end - - def samurai_display - super.display - end -end - - - diff --git a/derek_love/OOP/wiz_ninja_samurai/wizard.rb b/derek_love/OOP/wiz_ninja_samurai/wizard.rb deleted file mode 100644 index 36877aa..0000000 --- a/derek_love/OOP/wiz_ninja_samurai/wizard.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative 'human' - -class Wizard < Human - attr_accessor :strength, :intelligence, :stealth, :health - - def initialize - super() - @health = 50 - @intelligence = 25 - end - - def heal - @health += 10 - self - end - - def fireball(enemy) - if enemy.class.ancestors.include? Human - enemy.health -= 20 - else - "You fireballed a kitten!" - end - self - end - - def wiz_display - super.display - end -end - - diff --git a/derek_love/rubyFun/arrays.rb b/derek_love/rubyFun/arrays.rb deleted file mode 100644 index 948b56a..0000000 --- a/derek_love/rubyFun/arrays.rb +++ /dev/null @@ -1,27 +0,0 @@ -arr = ['a', 'b', 'c', 'd'] - -p arr.at(0) - -p arr.fetch(1) - -p arr.delete('d') - -p arr.reverse - -p arr.length - -arr = ['b', 'c', 'a'] - -p arr.sort - -p arr.slice(0..2) - -arr = [1, 2, 3, 4] - -p arr.shuffle - -p arr.join("-") - -p arr.insert(1, 'hello') - -vals = %w{dog doggo pupperoni}; p vals.values_at(1,2) \ No newline at end of file diff --git a/derek_love/rubyFun/basics.rb b/derek_love/rubyFun/basics.rb deleted file mode 100644 index 304cc58..0000000 --- a/derek_love/rubyFun/basics.rb +++ /dev/null @@ -1,87 +0,0 @@ -# 1 -# def numbers - # (1..255).each { |i| p i } -# end - -# 2 -# def odd_numbers - # (1..255).select { |i| p i if i.odd? } -# end - -# 3 -# def num_and_sum - # sum = 0 - - # (0..255).each { |i| sum += i; p "New number: #{i} Sum: #{sum}"} -# end - -# 4 -# def array arr - # arr.each { |i| p i } -# end -# array [1,3,7,14,57,19,43] - -# 5 -# def array_max arr - # p arr.max -# end -# array [1,3,-7,14,57,19,43] - -# 6 -# def average arr -# sum = 0 -# arr.each { |i| sum += i } -# p sum / arr.length -# end -# average [1,2,3,24,-20, 255] - -#7 -# def odd_array arr -# p arr.select { |i| i.odd? } -# end -# odd_array [1,2,3,4,5] - -#8 -# def greater_than_y arr, y -# num = 0; -# arr.select { |i| num += 1 if i > y } -# p num; -# end -# greater_than_y [1,3,4,5,6], 3 - -#9 -# def squares arr -# p arr.collect { |i| i*i } -# end -# squares [-2,2,3,25,10] - -#10 -# def no_negatives arr -# p arr.map { |i| i < 0 ? 0 : i } -# end -# no_negatives [-2,34,5,-20,4] - -#11 -# def min_max_avg arr -# sum = 0 -# arr.each { |i| sum += i } -# vals = {} -# vals[:min] = arr.min -# vals[:max] = arr.max -# vals[:avg] = sum / arr.length -# p vals -# end -# min_max_avg [1,2,3,4,5] - -#12 -# def shift arr -# arr.shift -# p arr -# end -# shift [1,2,3,4,5] - -#13 -# def num_to_str arr -# p arr.map { |i| i < 0 ? 'Dojo' : i} -# end -# num_to_str [-2,-4,2,-3,5] diff --git a/derek_love/rubyFun/enumerable.rb b/derek_love/rubyFun/enumerable.rb deleted file mode 100644 index c98ce93..0000000 --- a/derek_love/rubyFun/enumerable.rb +++ /dev/null @@ -1,12 +0,0 @@ -module MyEnumerable - def my_each - for i in 0...self.length - yield(self[i]) - end - end -end -class Array - include MyEnumerable# -end -[1,2,3,4].my_each { |i| p i } -[1,2,3,4].my_each { |i| p i * 10 } \ No newline at end of file diff --git a/derek_love/rubyFun/guess_number.rb b/derek_love/rubyFun/guess_number.rb deleted file mode 100644 index 97a012d..0000000 --- a/derek_love/rubyFun/guess_number.rb +++ /dev/null @@ -1,10 +0,0 @@ -def guess_number guess - number = 25 - if guess < number - puts "Guess was too low!" - elsif guess > number - puts "Guess was too high!" - else - puts "You got it!" - end -end diff --git a/derek_love/rubyFun/hashes.rb b/derek_love/rubyFun/hashes.rb deleted file mode 100644 index 4f060d5..0000000 --- a/derek_love/rubyFun/hashes.rb +++ /dev/null @@ -1,6 +0,0 @@ -hash_browns = { first_name: 'Coding', last_name: 'Dojo'} -hash_browns.delete(:last_name) -p hash_browns -p hash_browns.empty? -p hash_browns.has_key?(:first_name) -p hash_browns.has_value?('Dojo') \ No newline at end of file diff --git a/derek_love/rubyFun/names.rb b/derek_love/rubyFun/names.rb deleted file mode 100644 index a1fa398..0000000 --- a/derek_love/rubyFun/names.rb +++ /dev/null @@ -1,10 +0,0 @@ -a = {"first_name": "Michael", last_name: "Choi"} -b = {"first_name": "John", last_name: "Doe"} -c = {"first_name": "Jane", last_name: "Doe"} -d = {"first_name": "James", last_name: "Smith"} -e = {"first_name": "Jennifer", last_name: "Smith"} -names = [a, b, c, d, e] - -p "You have #{names.length} names in the 'names' array" - -names.each { |i| p "The name is '#{i[:first_name]} #{i[:last_name]}'"} \ No newline at end of file diff --git a/derek_love/rubyFun/puzzles.rb b/derek_love/rubyFun/puzzles.rb deleted file mode 100644 index 7fd278b..0000000 --- a/derek_love/rubyFun/puzzles.rb +++ /dev/null @@ -1,61 +0,0 @@ -#1 -# def array_sum_n_such arr -# sum = 0 -# arr.each { |i| sum += i } -# p sum - -# p arr.select { |i| i > 10 } -# end -# array_sum_n_such [3,5,1,2,7,9,8,13,25,32] - -#2 -# def shuffle arr -# arr.shuffle! -# arr.each { |i| p i } -# p arr.select { |i| i.length > 5 } -# end -# shuffle ['John', 'KB', 'Oliver', 'Cory', 'Matthew', 'Christopher'] - -#3 -# def alphabet -# arr = ('a'..'z').to_a -# vowels = ['a','e','i','o','u'] -# arr.shuffle! -# p arr.last -# p arr.first -# vowels.each { |i| p "you dirty vowel" if i == arr.first } -# end -# alphabet - -#4 -# def random -# arr = [] -# (1..10).collect { arr.push(rand(55..100)) } -# p arr -# end -# random - -#5 -# def random_sorted -# arr = [] -# (1..10).collect { arr.push(rand(55..100)) } -# arr.sort! -# p arr, arr.min, arr.max -# end -# random_sorted - -#6 -# def random_str -# str = ('a'..'z').to_a.shuffle[0,5].join -# p str -# end -# random_str - -#7 -# def arr_random -# arr = [] -# (1..10).collect { arr.push(('a'..'z').to_a.shuffle[0,5].join) } -# p arr -# end -# arr_random - diff --git a/derek_love/rubyFun/range.rb b/derek_love/rubyFun/range.rb deleted file mode 100644 index 8663290..0000000 --- a/derek_love/rubyFun/range.rb +++ /dev/null @@ -1,7 +0,0 @@ -p (1..10).include?(11) - -p ('a'..'z').last - -p (15..20).max - -p (-20..20).min \ No newline at end of file diff --git a/dillon_votaw/OOP/animals/dog.rb b/dillon_votaw/OOP/animals/dog.rb deleted file mode 100644 index aff3113..0000000 --- a/dillon_votaw/OOP/animals/dog.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative 'mammal' - -class Dog < Mammal - def pet - @health += 5 - self - end - def walk - @health -= 1 - self - end - def run - @health -= 10 - self - end -end - - -nani = Dog.new -nani.walk.walk.walk.run.run.pet.display_health \ No newline at end of file diff --git a/dillon_votaw/OOP/animals/lion.rb b/dillon_votaw/OOP/animals/lion.rb deleted file mode 100644 index d6e57e8..0000000 --- a/dillon_votaw/OOP/animals/lion.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative 'mammal' - -class Lion < Mammal - def initialize - super - @health = 170 - end - def fly - @health -= 10 - self - end - def attack_town - @health -= 50 - self - end - def eat_humans - @health += 20 - self - end - def display_health - puts "this lion" - super - end -end - - -pink = Lion.new -pink.attack_town.attack_town.attack_town.fly.fly.display_health \ No newline at end of file diff --git a/dillon_votaw/OOP/animals/mammal.rb b/dillon_votaw/OOP/animals/mammal.rb deleted file mode 100644 index 6f2d430..0000000 --- a/dillon_votaw/OOP/animals/mammal.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Mammal - def initialize - @health = 150 - end - def display_health - puts @health - self - end -end diff --git a/dillon_votaw/OOP/bank_account.rb b/dillon_votaw/OOP/bank_account.rb deleted file mode 100644 index 3f245a3..0000000 --- a/dillon_votaw/OOP/bank_account.rb +++ /dev/null @@ -1,75 +0,0 @@ -class BankAccount - @@no_of_accounts = 0 - def initialize - set_number - @checking = 0 - @savings = 0 - @interest_rate = 0 - end - - def get_number - puts @account_number - self - end - - def get_checking - puts @checking - self - end - - def get_savings - puts @savings - self - end - - def get_total - puts @savings + @checking - self - end - - def deposit_checking(amt) - @checking += amt - self - end - - def deposit_savings(amt) - @savings += amt - self - end - - def withdraw_checking(amt) - if amt < @checking - @checking -= amt - puts "you have withdrawn #{amt} from checking. #{@checking} remains" - else - puts "you dont have enuff" - end - self - end - - def withdraw_savings(amt) - if amt < @savings - @savings -= amt - puts "you have withdrawn #{amt} from savings. #{@savings} remains" - else - puts "you dont have enuff" - end - self - end - - def account_information - puts "your account number is #{@account_number}. your total money is #{@checking + @savings}. your checking balance is #{@checking} and your savings balance is #{@savings}. interest rate is #{@interest_rate}" - self - end - - - private - def set_number - @@no_of_accounts += 1 - @account_number = rand(1000..9999) - end - -end - -myAccount = BankAccount.new -myAccount.deposit_savings(1000).deposit_checking(2000).withdraw_savings(50).account_information diff --git a/dillon_votaw/OOP/human.rb b/dillon_votaw/OOP/human.rb deleted file mode 100644 index 2b193ba..0000000 --- a/dillon_votaw/OOP/human.rb +++ /dev/null @@ -1,82 +0,0 @@ -class Human - attr_accessor :strength, :intelligence, :health, :stealth - def initialize - @strength = 3 - @stealth = 3 - @intelligence = 3 - @health = 100 - end - def attack(target) - if target.class.ancestors.include? Human - puts 'yup' - target.health -= 10 - true - else - false - end - end -end - -class Wizard < Human - def initialize - super - @health = 50 - @intelligence = 25 - end - def heal - @health += 10 - self - end - def fireball(target) - target.health -= 20 - self - end -end - -class Ninja < Human - def initialize - super - @stealth = 175 - end - def steal(target) - attack(target) - @health += 10 - self - end - def get_away - @health -= 15 - self - end -end - -class Samurai < Human - @@samurai_count = 0 - def initialize - super - @health = 200 - @@samurai_count += 1 - end - def death_blow(target) - target.health = 0 - self - end - def meditate - @health = 200 - self - end - def how_many - puts "there are #{@@samurai_count} samurai" - end -end - -dillon = Human.new -nollid = Samurai.new -puts dillon.health -puts nollid.health -puts nollid.how_many -yuuup = Samurai.new -puts nollid.how_many #why does a space log after how many? its because puts returns nothing -nollid.death_blow(dillon) -puts dillon.health -dillon.attack(nollid) -puts nollid.health diff --git a/dillon_votaw/OOP/mathdojo.rb b/dillon_votaw/OOP/mathdojo.rb deleted file mode 100644 index 6af6c33..0000000 --- a/dillon_votaw/OOP/mathdojo.rb +++ /dev/null @@ -1,40 +0,0 @@ -class MethDojo - attr_accessor :result - def initialize - @result = 0 - end - def add *params - params.each do |i| - if i.is_a? Array - @result += i.reduce(:+) - else - @result += i - end - - end - self - end - def subtract *params - params.each do |i| - if i.is_a? Array - @result -= i.reduce(:+) - else - @result -= i - end - end - self - end -end - -puts challenge1 = MethDojo.new.add(2).add([2, 3], 5).subtract(3, 2).result - -puts challenge2 = MethDojo.new.add(1).add([3, 5, 7, 8], [2, 4.3, 1.25]).subtract([2,3], [1.1, 2.3]).result - - -# def splatting *params -# params -# end -# puts splatting(1).inspect # => [1] -# puts splatting(1, 2, 3, 4, 5).inspect # => [1, 2, 3, 4, 5] -# puts splatting([1, 2, 3], 4, 5).inspect -# => All the arguments are condensed into a single array. \ No newline at end of file diff --git a/dillon_votaw/OOP/oop_examples.rb b/dillon_votaw/OOP/oop_examples.rb deleted file mode 100644 index 19e36e3..0000000 --- a/dillon_votaw/OOP/oop_examples.rb +++ /dev/null @@ -1,121 +0,0 @@ -# class User -# def first_name=(val) # setter -# @first_name = val -# end -# def first_name #getter -# @first_name -# end -# attr_reader :last_name -# attr_writer :last_name -# end - -# class User -# attr_accessor :first_name, :last_name #handles getter and setter (reader and writer) -# def initialize(f_name, l_name) -# @first_name = f_name -# @last_name = l_name -# end - -# def full_name -# puts "I am #{@first_name} #{@last_name}" -# end - -# def say_hello -# puts "ay" -# end - -# def self.foo -# puts "this be a class method" -# end -# end - -# nollid = User.new("nollid", "watov") - -# nollid.full_name -# nollid.say_hello - -# nollid.foo (doesn't work bc foo is a class method, not an instance method) -# User.foo - -class CodingDojo - @@no_of_branches = 0 - def initialize(id, name, address) - @branch_id = id - @branch_name = name - @branch_address = address - @@no_of_branches += 1 - puts "Created branch #{@@no_of_branches}" - end - def hello - puts "Hello CodingDojo!" - end - def display_all - puts "Branch ID: #{@branch_id}" - puts "Branch Name: #{@branch_name}" - puts "Branch Address: #{@branch_address}" - end -end -# now using above class to create objects -branch = CodingDojo.new(253, "SF CodingDojo", "Sunnyvale CA") -branch.display_all -branch2 = CodingDojo.new(155, "Boston CodingDojo", "Boston MA") -branch2.display_all - - -# class Fixnum -# def who_am_i -# puts self -# end -# end -# class String -# def who_am_i -# puts self -# end -# end -# 4.who_am_i # => 4 -# 15.who_am_i # => 15 -# "string".who_am_i # => "string" -# "hello_world".who_am_i # => "hello_world" - -# class Mammal -# def initialize -# puts "I am alive" -# self -# end -# def breath -# puts "Inhale and exhale" -# self -# end - -# def who_am_i -# # printing the current object -# puts self -# self -# end -# end -# my_mammal = Mammal.new # => "I am alive" -# my_mammal.who_am_i # => # -# my_mammal.who_am_i.breath - - -class Mammal - def breath - puts "Inhale and exhale" - end - - def eat - puts "Yum yum yum" - end -end -class Human < Mammal # Human inherits from Mammal - def subclass_method - breath - end - def another_method - eat - end -end -person = Human.new -person.subclass_method -person.another_method - diff --git a/dillon_votaw/OOP/project.rb b/dillon_votaw/OOP/project.rb deleted file mode 100644 index d2c4a02..0000000 --- a/dillon_votaw/OOP/project.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Project - attr_accessor :name, :desc - def initialize(name, desc) - @name = name - @desc = desc - end - def elevator_pitch - puts "i would love nothing more than to leave this elevator. #{@desc}" - end -end - -project1 = Project.new("Cool shit", "Very cool") -puts project1.name -project1.elevator_pitch - diff --git a/dillon_votaw/fundamentals/arrays.rb b/dillon_votaw/fundamentals/arrays.rb deleted file mode 100644 index 420ee1c..0000000 --- a/dillon_votaw/fundamentals/arrays.rb +++ /dev/null @@ -1,24 +0,0 @@ -a = [1, 2, 3, 4] -b = ["ichi", "ni", "san", "yon"] - -# c = a+b -# puts c.to_s -# puts b.shuffle.join("-") -# puts b.values_at(0,3).join(' and ') - -# a.delete(4) -# puts a - -# puts a.length -# puts a.reverse.to_s -# puts a.at(0) - -# c = ["d", "b", "a", "c"] - -# puts c.sort.to_s - -# puts a.slice(1) - -# puts b.join(" ") - -# puts b.insert(4, "go") \ No newline at end of file diff --git a/dillon_votaw/fundamentals/basic_13.rb b/dillon_votaw/fundamentals/basic_13.rb deleted file mode 100644 index 8dedf92..0000000 --- a/dillon_votaw/fundamentals/basic_13.rb +++ /dev/null @@ -1,104 +0,0 @@ -# //1// -# (1..255).each { |i| print i, " " } - -#//2// -# puts (1..255).find_all { |i| i % 2 == 1 }.to_s - -#//3// -# sum = 0 -# for i in 0..255 -# sum += i -# puts "New number: #{i} Sum #{sum}" -# end - -#//4// -# x = [1,3,5,7,9,13] - -# for i in 0..x.length-1 -# puts x[i] -# end - -#//5// -# def find_max(arr) -# arr.sort! -# return arr[arr.length-1] -# end - -# puts find_max([-1,-3,5,-7,-9,-13]) - -#//6// -# def get_average(arr) -# sum = 0 -# for i in 0..arr.length-1 -# sum += arr[i] -# end -# return sum/arr.length -# end - -# puts get_average([2,10,3]) - -# //7// -# def odd_array -# y = [] -# y = (1..255).find_all { |i| i.odd? } # DOPE -# return y -# end - -# puts odd_array - -# #//8// -# def greater_than(arr, y) -# sum = arr.find_all { |i| i > y }.length #damn so clean (dont forget last evaluation is returned) -# end -# puts greater_than([1,3,5,7,9], 3) - -#//9// -# def square_city(arr) -# arr.collect { |i| i*i } -# end - -# puts square_city([1,5,10,-2]) - -#//10// - -# def no_negatives(arr) -# arr.collect { |i| if i < 0 then 0 else i end } #this works because we are forming a new array with the return from the block function -# end - -# puts no_negatives([3,5,-23,5,-66]) - -#//11// - -# def maxminavg(arr) -# sum = 0 -# arr.sort! -# min = arr[0] -# max = arr[arr.length-1] -# for i in 0..arr.length-1 -# sum += arr[i] -# end -# avg = sum/arr.length -# return { min: min, max: max, avg: avg } -# end - -# puts maxminavg([-2,100,5,5,5]) - -#//12// - -# def shiftur(arr) #have to use a for loop bc we wanna look at indexes -# for i in 0..arr.length-1 -# arr[i] = arr[i+1] -# if arr[i] == nil then arr[i] = 0 end -# end -# return arr -# end - -# puts shiftur([2,5,7,9]) - -#//13// -# def numtostring(arr) -# arr.collect { |i| if i.is_a? Numeric then "w00t" else i end } -# end - -# puts numtostring(["666",1,2,3,"666"]) - diff --git a/dillon_votaw/fundamentals/guess_the_number.rb b/dillon_votaw/fundamentals/guess_the_number.rb deleted file mode 100644 index 4389359..0000000 --- a/dillon_votaw/fundamentals/guess_the_number.rb +++ /dev/null @@ -1,12 +0,0 @@ -def guess_number guess - number = 25 - - return "got it" unless guess > number || guess < number - return "too low" unless guess > number - return "too high" - -end - -puts guess_number 25 -puts guess_number 2 -puts guess_number 30 \ No newline at end of file diff --git a/dillon_votaw/fundamentals/hajime.rb b/dillon_votaw/fundamentals/hajime.rb deleted file mode 100644 index 69e8f43..0000000 --- a/dillon_votaw/fundamentals/hajime.rb +++ /dev/null @@ -1,189 +0,0 @@ -# /// PUTS /// -# 3.times { puts "~" } - -# BEGIN { -# puts "this will run first" -# } - -# END { -# puts "this will run last" -# } - - -# first_name = "shithead" -# last_name = "whatever" - -# puts "Your name is "+first_name+" "+last_name -# puts "First name is #{first_name} and last name is #{last_name}" - -# puts "lets do some \"internal quotes\" " - - -# /// STRINGS /// - -# x = "fuck off" - -# puts x -# puts x.length; puts x.class; puts x.capitalize; puts x.upcase; puts x.downcase; - -# puts x[2]; puts x.include?("off"); #include? is case sensitive -# puts "off in it" if x.include? "off" - -# x = "why, am, i, alive" -# y = "" -# puts x.split(",") -# puts "Y is empty" if y.empty? #use question mark functions along with if statements - -#must attach bang (!) to string methods if want to alter value of original string - -# /// CONDITIONALS /// - -# x=2 - -# if x > 2 -# puts "x greater than 2" -# elsif x < 2 and x > 0 -# puts "x is 1" -# else -# puts "idk" -# end -#parenthesis are optional, semicolons are optional - -# x=5 - -# puts "x is not 2" if x != 2 -# puts "x is greater than 2" if x > 2 -# puts "x is not 2" unless x==2 #AWESOME - -# $age = 2 #global variable -# age = 21 #local variable - -# case age -# when 0 .. 2 -# puts "bb" -# when 3 .. 6 -# puts "lil bb" -# when 7 .. 12 -# puts "child" -# when 13 .. 18 -# puts "yoof" -# else -# puts "grown" -# end - -# /// LOOPS /// -#while loop -# i = 0 -# num = 5 -# while i < num do -# puts "Inside the loop i = #{i}" -# i +=1 -# end - -#using break -# i = 0 -# num = 5 -# while i < num do -# puts "Inside the loop i = #{i}" -# i += 1 -# break if i == 2 -# end - - -# for loop -# for i in 0..5 -# puts "Value of local variable is #{i}" -# end - -# using next -# for i in 0..5 -# next if i == 2 -# puts "Value of local variable is #{i}" -# end - - -# /// METHODS /// - -# def hello_world -# puts "goodbye world" -# end -# hello_world - #nice - -# def use_inputs(input1, input2) -# puts "fuckkk yeah #{input1} and #{input2}" -# end -# use_inputs("hey", "you") - -# def say_hello name1="oscar", name2="shane" -# "hello, #{name1} and #{name2}" -# end -# puts say_hello "oscar", "eduardo" # => "hello, oscar and eduardo" -# ^ruby by default returns whatever was evaluated last - -# /// ITERATORS /// - - -# puts ["ant", "bear", "cat"].any? { |word| word.length >= 3 } # true - -# ["ant", "bear", "cat"].each { |word| print word, "--" } # => ant--bear--cat-- - -# puts (1..4).collect { |i| i*i } # => [1, 4, 9, 16] -# puts (1..4).collect { "cat" } # => ["cat", "cat", "cat", "cat"] - -# puts (1..10).detect { |i| i %5 == 0 and i % 7 == 0 } # => nil -# puts (1..100).detect { |i| i %5 == 0 and i % 7 == 0 } # => 35 - -# puts (1..10).find_all { |i| i % 3 == 0 }.to_s # => [3, 6, 9] - -# puts (1..10).reject { |i| i % 3 == 0 }.to_s # => [1, 2, 4, 5, 7, 8, 10] - -# 5.upto(10) { |i| print i, " " } # => 5 6 7 8 9 10 - -# /// YIELD AND BLOCK STATEMENTS /// - -# def test -# puts "You are in the method" -# yield # RUN THE BLOCK -# puts "You are again back to the method" -# yield # -# end -# test { puts "You are in the block" } #in curly is a BLOCK - - -#check it out WE CAN PASS A PARAMETER TO THE BLOCK -# def test -# yield 5 -# puts "You are in the method test" -# yield 100 -# end -# test { |i| puts "You are in the block #{i}" } - - -#BELOW COOL AND IMPORTANT -# def square(num) -# puts "num is #{num}" -# puts "yield(num) has a value of #{yield(num)}" - -# x = yield(num) -# puts "x is #{x}" - -# y = yield(num)*x -# puts "y is #{y}" -# end - -# square(5) {|i| i*i } - - - - - -## DIFFERENT SYNTAX FOR ITERATORS -(1..200).each do |i| - p i if i % 2 == 1 -end - - - - - diff --git a/dillon_votaw/fundamentals/hashes.rb b/dillon_votaw/fundamentals/hashes.rb deleted file mode 100644 index 03801ce..0000000 --- a/dillon_votaw/fundamentals/hashes.rb +++ /dev/null @@ -1,8 +0,0 @@ -hash_pipe = { hello: "goodbye", imsad: "justkidding", imalways: "sohappy", tobe: "alive" } - -puts hash_pipe - -hash_pipe.delete(:hello); puts hash_pipe - -puts hash_pipe.empty?; puts hash_pipe.has_key?(:major_key) -puts hash_pipe.has_value?("justkidding") \ No newline at end of file diff --git a/dillon_votaw/fundamentals/module_practice/main.rb b/dillon_votaw/fundamentals/module_practice/main.rb deleted file mode 100644 index 2438fd4..0000000 --- a/dillon_votaw/fundamentals/module_practice/main.rb +++ /dev/null @@ -1,12 +0,0 @@ -require_relative 'printer_module' -class Array - include Printer -end -class String - include Printer -end -[1,2,3].print_each_element -"hello".print_each_element - -puts Array.ancestors.to_s -puts Hash.ancestors.to_s \ No newline at end of file diff --git a/dillon_votaw/fundamentals/module_practice/my_enumerable.rb b/dillon_votaw/fundamentals/module_practice/my_enumerable.rb deleted file mode 100644 index 3e6783c..0000000 --- a/dillon_votaw/fundamentals/module_practice/my_enumerable.rb +++ /dev/null @@ -1,12 +0,0 @@ -module MyEnumerable - def my_each - for i in 0..self.length-1 - yield self[i] - end - end -end -class Array - include MyEnumerable -end -[1,2,3,4].my_each { |i| puts i } # => 1 2 3 4 -[1,2,3,4].my_each { |i| puts i * 10 } # => 10 20 30 40 diff --git a/dillon_votaw/fundamentals/module_practice/printer_module.rb b/dillon_votaw/fundamentals/module_practice/printer_module.rb deleted file mode 100644 index d672d19..0000000 --- a/dillon_votaw/fundamentals/module_practice/printer_module.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Printer - def print_each_element - for i in 0...self.length - puts self[i] - end - end -end diff --git a/dillon_votaw/fundamentals/names.rb b/dillon_votaw/fundamentals/names.rb deleted file mode 100644 index 2b0696e..0000000 --- a/dillon_votaw/fundamentals/names.rb +++ /dev/null @@ -1,18 +0,0 @@ -a = {first_name: "Michael", last_name: "Choi"} -b = {first_name: "John", last_name: "Doe"} -c = {first_name: "Jane", last_name: "Doe"} -d = {first_name: "James", last_name: "Smith"} -e = {first_name: "Jennifer", last_name: "Smith"} -names = [a, b, c, d, e] - - -def namer(arr) - puts "You have #{arr.length} names in the 'names' array" - arr.each { |i| puts "namae wa #{i[:first_name]} #{i[:last_name]}" } - -end - - -namer(names) - - diff --git a/dillon_votaw/fundamentals/range.rb b/dillon_votaw/fundamentals/range.rb deleted file mode 100644 index 34850fa..0000000 --- a/dillon_votaw/fundamentals/range.rb +++ /dev/null @@ -1,8 +0,0 @@ -x = (1..10) - - -puts x.include? 3 - -puts x.last - -puts x.max; puts x.min \ No newline at end of file diff --git a/dillon_votaw/fundamentals/ruby_puzzles.rb b/dillon_votaw/fundamentals/ruby_puzzles.rb deleted file mode 100644 index f1dd4bb..0000000 --- a/dillon_votaw/fundamentals/ruby_puzzles.rb +++ /dev/null @@ -1,64 +0,0 @@ -# x = [3,5,1,2,7,9,8,13,25,32] -# def one(arr) -# sum = 0 -# arr.each {|i| sum += i } -# print sum, "\n" -# return arr.find_all { |i| i > 10 } -# end - -# puts one(x) -# ~~~~ - -# x = ["John", "RageKage", "Oliver", "Tory", "Matthias", "Christophe"] - -# def two(arr) -# arr.shuffle.each { |i| print i, "--"} -# return arr.find_all { |i| i.length > 5 } -# end - -# puts two(x) -# ~~~~ - -# x = ('a'..'z').to_a # NICE NICE NICE - -# def three(arr) -# arr.shuffle! -# puts arr.last; puts arr.first; -# if arr.first == 'a' || arr.first == 'e' || arr.first == 'i' || arr.first == 'o' || arr.first == 'u' -# puts "ohhh yeahhhhhhhh hHYESSS YES YES YES" -# end -# end - -# three(x) -# ~~~~~ - -# x = [] -# for i in 0..9 -# x.push(rand(55..100)) -# end -# puts x.to_s -# ~~~~~~ - -# x = [] -# for i in 0..9 -# x.push(rand(55..100)) -# end -# x.sort! -# puts x.to_s; puts x.first; puts x.last -# ~~~~~~~ - -# x = "" -# for i in 0..4 -# x << (65+rand(26)).chr -# end -# puts x -# ~~~~~~~~ -# arr = [] -# for i in 0..9 -# x = "" -# for i in 0..4 -# x << (65+rand(26)).chr -# end -# arr.push(x) -# end -# puts arr.to_s diff --git a/kyla_stearns/Fundamentals/arrays.rb b/kyla_stearns/Fundamentals/arrays.rb deleted file mode 100644 index 2f38ca1..0000000 --- a/kyla_stearns/Fundamentals/arrays.rb +++ /dev/null @@ -1,38 +0,0 @@ -# .at -arr = [3,6,1,8,13] -p arr.at(1) -# should output => 6 - -# .fetch -p arr.fetch(3) -# should output => 8 - -# .delete -# p arr -arr.delete(1) -# p arr - -# .reverse -- # add ! after if you want to actually change the value to the new reversed array -p arr.reverse - -# .length -p arr.length - -# .sort -- # add ! after if you want to actually change the value to the new reversed array -p arr.sort - -# .slice -- slices AFTER the index you give it -- add ! after if you want to actually change the value to the new reversed array -p arr.slice(3) - -# .shuffle -- add ! after if you want to actually change the value to the new reversed array -# randomly shuffles indexes -p arr.shuffle - -# .join -p arr.join('-') - -# .insert -- indicate index to add at and what to add -p arr.insert(2, "snacks") - -# values_at -p arr.values_at(0,2,4) \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/basic13.rb b/kyla_stearns/Fundamentals/basic13.rb deleted file mode 100644 index 5b5e2d8..0000000 --- a/kyla_stearns/Fundamentals/basic13.rb +++ /dev/null @@ -1,89 +0,0 @@ -# Print 1-255 -p (1..255).to_a - -# Print odd numbers between 1-255 -(1..255).to_a.select { |elem| p elem if elem.odd? } - -# Print Sum -def print_sum - sum = 0 - for i in (1..255) - p "Number: #{i} and Sum: #{sum = sum + i}" - end -end -print_sum - -# Iterating through an array -x = [1,3,5,7,9,13] -x.each { |i| p i } - -# Find Max -def find_max arr - p arr.max -end -find_max [2,4,8,1,99] - -# Get Average -def avg arr - # to_f will account for uneven division - p arr.reduce(:+).to_f / arr.size -end -avg [2,10,3] - -# Array with odd numbers -(1..255).to_a { |i| y = y.push(i) p y i.odd? } -y = [] -(1..255).to_a.select { |elem| y.push(elem) if elem.odd? } -p y - -# Greater than Y -def greater arr, y - new = [] - arr.select { |i| new.push(i) if i > y } - p new -end -greater [1,3,5,7], 3 - -# Square the values -def square arr - y = [] - arr.select { |i| y.push(i*i) } - p y -end -square [1,5,10,-2] - -# Eliminate negatives -def eliminate arr - arr.each_index { |i| arr[i] = 0 if arr[i] < 0} - p arr -end -eliminate [1,5,10,-2] - -# Max, Min, and Average -def hash arr - arr_hash = {max: arr.max, min: arr.min, avg: arr.reduce(:+).to_f / arr.size } - p arr_hash -end -hash [1,5,10,-2] - -# Shifting -def shift arr - arr.shift - arr.push(0) - p arr -end -shift [1,5,10,7,-2] - -# OR -def shift arr - arr.rotate! - p arr -end -shift [1,5,10,7,-2] - -# Number to String -def string arr - arr.each_index { |i| arr[i] = "Dojo" if arr[i] < 0} - p arr -end -string [-1,-3,2] diff --git a/kyla_stearns/Fundamentals/guess.rb b/kyla_stearns/Fundamentals/guess.rb deleted file mode 100644 index 9d5054b..0000000 --- a/kyla_stearns/Fundamentals/guess.rb +++ /dev/null @@ -1,8 +0,0 @@ -def guess_number guess - number = 25 - p "You got it!" unless guess != number - p "Guess was too high!" if guess > number - p "Guess was too low!" if guess < number -end - -guess_number(25) \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/hashes.rb b/kyla_stearns/Fundamentals/hashes.rb deleted file mode 100644 index 670aaaa..0000000 --- a/kyla_stearns/Fundamentals/hashes.rb +++ /dev/null @@ -1,18 +0,0 @@ -# .delete(key) => deletes and returns a value associated with the key -names = {first_name: "Kyla", last_name: "Stearns"} -p names.delete('last_name') -# Definitely is not working how explained in 2.3.1 documentation :-/ -p names # => {:first_name => "Kyla"} - -# .empty? => returns true if hash contains no key-value pairs -names = {first_name: "Kyla", last_name: "Stearns"} -p names.empty? - -# .has_key?(key) => true or false -names = {first_name: "Kyla", last_name: "Stearns"} -p names.has_key?('fav_color') - -# .has_value?(value) => true or false -names = {first_name: "Kyla", last_name: "Stearns"} -p names.has_value?('kyla') -p names.has_value?('Kyla') \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/myEnumerables.rb b/kyla_stearns/Fundamentals/myEnumerables.rb deleted file mode 100644 index 494da08..0000000 --- a/kyla_stearns/Fundamentals/myEnumerables.rb +++ /dev/null @@ -1,10 +0,0 @@ -module MyEnumerable - def my_each - # your code here! - end -end -class Array - include MyEnumerable -end -[1,2,3,4].my_each { |i| puts i } # => 1 2 3 4 -[1,2,3,4].my_each { |i| puts i * 10 } # => 10 20 30 40 diff --git a/kyla_stearns/Fundamentals/names.rb b/kyla_stearns/Fundamentals/names.rb deleted file mode 100644 index 340edb4..0000000 --- a/kyla_stearns/Fundamentals/names.rb +++ /dev/null @@ -1,12 +0,0 @@ -a = {first_name: "Michael", last_name: "Choi"} -b = {first_name: "John", last_name: "Doe"} -c = {first_name: "Jane", last_name: "Doe"} -d = {first_name: "James", last_name: "Smith"} -e = {first_name: "Jennifer", last_name: "Smith"} -all_names = [a, b, c, d, e] - -def name_list arr - p "You have #{arr.length} names in the 'names' array " - arr.each { |i| p "The name is '#{i[:first_name]} #{i[:last_name]}' "} -end -name_list all_names \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/puzzles.rb b/kyla_stearns/Fundamentals/puzzles.rb deleted file mode 100644 index e8b37e9..0000000 --- a/kyla_stearns/Fundamentals/puzzles.rb +++ /dev/null @@ -1,58 +0,0 @@ -# 1 -def info arr - sum = 0 - arr.each { |x| sum = sum + x } - p "Sum: #{sum}" - new_arr = [] - arr.find_all { |i| new_arr.push(i) if i > 10 } - p "Above 10: #{new_arr}" -end -info [3,5,1,2,7,9,8,13,25,32] - -# 2 -names = ["John", "KB", "Oliver", "Cory", "Matthew", "Christopher"] -names.shuffle.each { |elem| p elem } -long_names = [] -names.find_all { |long| long_names.push(long) if long.length > 5 } -p long_names - -# 3 -x = ('a'..'z').to_a -x.shuffle! -p x, x[-1], x[0] -can also say x.last and x.first -vowels = ['a','e','i','o','u'] -vowels.each { |i| p "It's a vowel" if i == x[0] } - -# 4 -random = [] -for i in 0..9 - random.push(rand(55..100)) -end -p random - -# 5 -random = [] -for i in 0..9 - random.push(rand(55..100)) -end -random.sort! -p random, random.min, random.max - -# 6 -string = '' -for i in 0..4 - string += (65+rand(26)).chr -end -p string - -# 7 -random = [] -for i in 0..9 - string = '' - for x in 0..4 - string += (65+rand(26)).chr - end - random.push(string) -end -p random \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/range.rb b/kyla_stearns/Fundamentals/range.rb deleted file mode 100644 index 8f8dd12..0000000 --- a/kyla_stearns/Fundamentals/range.rb +++ /dev/null @@ -1,13 +0,0 @@ -# .include?(value) -- looks for input value and returns Boolean -names = ["bobby", "cindy", "billy"] -p names.include?('berta') -p names.include?('bobby') - -# .last -- last value in array -p names.last - -# .max -- returns max value in range -p (1..10).max - -# .min -- returns min value in range -p (2..20).min \ No newline at end of file diff --git a/kyla_stearns/Fundamentals/symbols.rb b/kyla_stearns/Fundamentals/symbols.rb deleted file mode 100644 index e69de29..0000000 diff --git a/shane_fisher/fundamentals/GuessTheNumber.rb b/shane_fisher/fundamentals/GuessTheNumber.rb deleted file mode 100644 index 12519d7..0000000 --- a/shane_fisher/fundamentals/GuessTheNumber.rb +++ /dev/null @@ -1,11 +0,0 @@ -# just exercise - -def guess_number guess_number - number = 25 - puts "You got it!" if guess_number == number - puts "Guess was too high!" if guess_number > number - puts "Guess was too low!" if guess_number < number -end - - - diff --git a/shane_fisher/fundamentals/basic13.rb b/shane_fisher/fundamentals/basic13.rb deleted file mode 100644 index f0472f9..0000000 --- a/shane_fisher/fundamentals/basic13.rb +++ /dev/null @@ -1,120 +0,0 @@ -# print 1-255 - -(1..255).each {|num| puts num} - -# print odd between 1-255 - -(1..255).each { |num| puts num if num.odd?} - -# print Sum - -puts (1..255).reduce(:+) - -# print Sum with output - -sum = 0 -(0..255).each { |num| puts "New number: " + num.to_s + " Sum: #{sum + num}"; sum += num } - -# Iterating through an array - -def through(arr) - arr.each { |index| puts index} -end - -through([1,2,5,6,8]) - -# Find Max - -def find_max(arr) - puts arr.max -end - -find_max([5,9,15,22,3]) - -# Get Average - -def get_avg(arr) - sum = arr.reduce(:+) - avg = sum / arr.length - puts "The average of the array is #{ avg }" -end - -get_avg([2,10,3,15]) - -# Array with Odd Numbers - -y = (1..255).find_all { |i| i.odd? } -p y - -# Greater Than Y - -def greater(arr, y) - puts arr.count { |i| i > y} -end - -greater([5,3,1,18,4], 3) - -# Square the Values - -def square(arr) - arr.map! { |i| i * i } - p arr -end - -square([2,4,10,50]) - -# Eliminate Negatives - -def no_neg(arr) - arr.map! { |i| - if (i < 0) - 0 - else - i - end - } - p arr -end - -no_neg([-2,5,-15,13,20,-8]) - -# Max,Min, Average - -def mma(arr) - max = arr.max - min = arr.min - sum = arr.reduce(:+) - avg = sum / arr.length - p max, min, avg -end - -mma ([12, 49, 3, 10]) - -# Shift the Values - -def change(arr) - arr.shift - arr << 0 - p arr -end - -change ([1,3,8,9,10]) - -# Number to String - -def no_neg(arr) - arr.map! { |i| - if (i < 0) - "Dojo" - else - i - end - } - p arr -end - -no_neg([-2,5,-15,13,20,-8]) - - - - diff --git a/shane_fisher/fundamentals/names.rb b/shane_fisher/fundamentals/names.rb deleted file mode 100644 index 4edf882..0000000 --- a/shane_fisher/fundamentals/names.rb +++ /dev/null @@ -1,14 +0,0 @@ -a = {first_name: "Michael", last_name: "Choi"} -b = {first_name: "John", last_name: "Doe"} -c = {first_name: "Jane", last_name: "Doe"} -d = {first_name: "James", last_name: "Smith"} -e = {first_name: "Jennifer", last_name: "Smith"} -names = [a, b, c, d, e] - - -def names (arr) - puts "You have #{arr.count} names in the 'names' array" - arr.each { |name| puts "The name is '#{name[:first_name]} #{name[:last_name]}'"} -end - -names(names) \ No newline at end of file diff --git a/shane_fisher/fundamentals/range.rb b/shane_fisher/fundamentals/range.rb deleted file mode 100644 index 4c97841..0000000 --- a/shane_fisher/fundamentals/range.rb +++ /dev/null @@ -1,6 +0,0 @@ -x = (4..24) - -puts x.last -puts x.max -puts x.min -puts x.include?(25) \ No newline at end of file diff --git a/shane_fisher/fundamentals/rubypuzzles.rb b/shane_fisher/fundamentals/rubypuzzles.rb deleted file mode 100644 index 3f469fb..0000000 --- a/shane_fisher/fundamentals/rubypuzzles.rb +++ /dev/null @@ -1,97 +0,0 @@ -# Puzzle 1 - -def puzzle1() -arr = [3,5,1,2,7,9,8,13,25,32] -p arr.reduce(:+) -newarr = arr.reject {|i| i < 10} -p newarr -end - -puzzle1 - -# Puzzle 2 - -def puzzle2() - arr = ['John', 'KB', 'Oliver', 'Cory', 'Matthew', 'Christopher'] - arr.shuffle! - arr.each { |name| p name} - newarr = arr.reject { |name| name.length < 6} - p newarr - -end - -puzzle2 - -# Puzzle 3 - -def puzzle3() - - letters = ('a'..'z') - - arr = letters.to_a.shuffle! - p arr - p arr.last - p arr.first - if arr.first.to_s.start_with?("a", "e", "i", "o", "u") - puts "First letter is a vowel. Letter is #{arr.first}" - end - -end - -puzzle3 - -# Puzzle 4 - -def puzzle4() - arr = [] - 10.times do - num = rand(55..255) - arr << num - end - p arr -end - -puzzle4 - -# Puzzle 5 - -def puzzle5() - arr = [] - 10.times do - num = rand(55..255) - arr << num - end - p arr.sort, arr.min, arr.max -end - -puzzle5 - -# Puzzle 6 - -def puzzle6() - mystr = "" - 5.times do - letter = (65+rand(26)).chr - mystr << letter - end - p mystr -end - -puzzle6 - -# Puzzle 7 - -def puzzle7() - arr = [] - 10.times do - mystr = "" - 5.times do - letter = (65+rand(26)).chr - mystr << letter - end - arr << mystr - end - p arr -end - -puzzle7 diff --git a/shane_fisher/oop/Dog/dog.rb b/shane_fisher/oop/Dog/dog.rb deleted file mode 100644 index 294511a..0000000 --- a/shane_fisher/oop/Dog/dog.rb +++ /dev/null @@ -1,17 +0,0 @@ -require_relative 'mammal' - -class Dog < Mammal - def pet - @health += 5 - self - end - def walk - @health -= 1 - self - end - def run - @health -= 10 - self - end - -end diff --git a/shane_fisher/oop/Dog/mammal.rb b/shane_fisher/oop/Dog/mammal.rb deleted file mode 100644 index 60a41e8..0000000 --- a/shane_fisher/oop/Dog/mammal.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Mammal - attr_accessor :health - - def initialize - @health = 150 - end - - def display_health - p @health - end -end \ No newline at end of file diff --git a/shane_fisher/oop/Human/human.rb b/shane_fisher/oop/Human/human.rb deleted file mode 100644 index 4ed8de5..0000000 --- a/shane_fisher/oop/Human/human.rb +++ /dev/null @@ -1,26 +0,0 @@ -class Human - attr_accessor :str, :int, :stealth, :health - def initialize - @str = 3 - @int = 3 - @stealth = 3 - @health = 100 - end - - def attack(object) - if object.class.ancestors.include? Human - object.health -= 10 - puts "Target has #{object.health} left." - self - - else - puts "You can't attack a non-Human" - self - end - end - -end - -Eric = Human.new -Todd = Human.new -Eric.attack(Todd).attack(Todd).attack(Todd) \ No newline at end of file diff --git a/shane_fisher/oop/Lion/lion.rb b/shane_fisher/oop/Lion/lion.rb deleted file mode 100644 index ddcc615..0000000 --- a/shane_fisher/oop/Lion/lion.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative 'mammal' - -class Lion < Mammal - def initialize - @health = 170 - self - end - - def fly - @health -= 10 - self - end - - def attack_town - @health -= 50 - self - end - - def eat_humans - @health += 20 - self - end - - def lion_health - p "This is a lion" - display_health - self - end -end \ No newline at end of file diff --git a/shane_fisher/oop/Lion/mammal.rb b/shane_fisher/oop/Lion/mammal.rb deleted file mode 100644 index 60a41e8..0000000 --- a/shane_fisher/oop/Lion/mammal.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Mammal - attr_accessor :health - - def initialize - @health = 150 - end - - def display_health - p @health - end -end \ No newline at end of file diff --git a/shane_fisher/oop/MathDojo.rb b/shane_fisher/oop/MathDojo.rb deleted file mode 100644 index 6a2af9b..0000000 --- a/shane_fisher/oop/MathDojo.rb +++ /dev/null @@ -1,17 +0,0 @@ -class MathDojo - attr_accessor :result - def initialize - @result = 0 - end - def add (*params) - @result += params.flatten.reduce(:+) - self - end - def subtract (*params) - @result -= params.flatten.reduce(:+) - self - end - -end -puts challenge1 = MathDojo.new.add(2).add(2, 5).subtract(3, 2).result # => 4 -puts challenge2 = MathDojo.new.add(1).add([3, 5, 7, 8], [2, 4.3, 1.25]).subtract([2,3], [1.1, 2.3]).result # => 23.15 \ No newline at end of file diff --git a/shane_fisher/oop/Project.rb b/shane_fisher/oop/Project.rb deleted file mode 100644 index 38e44f8..0000000 --- a/shane_fisher/oop/Project.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Project - attr_accessor :name, :description - def initialize(name, desc) - @name = name - @description = desc - end - def elevator_pitch - #Liberty taken with output instead of generic comma - puts "My project is #{ @name } and it is #{ @description }" - end -end -project1 = Project.new("Weebles and Wobbles", "Amazingly Awesome") -puts project1.name # => "Weebles and Wobbles" -project1.elevator_pitch # => "Project 1, Description 1" - - diff --git a/shane_fisher/oop/WNS/human.rb b/shane_fisher/oop/WNS/human.rb deleted file mode 100644 index 4e9f844..0000000 --- a/shane_fisher/oop/WNS/human.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Human - attr_accessor :str, :int, :stealth, :health - def initialize - @str = 3 - @int = 3 - @stealth = 3 - @health = 100 - end - - def attack(object) - if object.class.ancestors.include? Human - object.health -= 10 - puts "Target has #{object.health} left." - self - - else - puts "You can't attack a non-Human" - self - end - end - -end diff --git a/shane_fisher/oop/WNS/ninja.rb b/shane_fisher/oop/WNS/ninja.rb deleted file mode 100644 index 72a63fe..0000000 --- a/shane_fisher/oop/WNS/ninja.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative "human" - -class Ninja < Human - -def initialize - super() - @health = 175 -end - -def steal(object) - object.health -= 10 - @health += 10 -end - -def get_away - @health -= 15 -end - -end \ No newline at end of file diff --git a/shane_fisher/oop/WNS/samurai.rb b/shane_fisher/oop/WNS/samurai.rb deleted file mode 100644 index df5fb43..0000000 --- a/shane_fisher/oop/WNS/samurai.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative "human" - -class Samurai < Human -@@total_sams = 0 - -def initialize - super() - @health = 200 - @@total_sams += 1 -end - -def death_blow(object) - object.health = 0 - self -end - -def meditate(object) - @health = 200 - self -end - -def how_many() - return @@total_sams - self -end - -end diff --git a/shane_fisher/oop/WNS/wizard.rb b/shane_fisher/oop/WNS/wizard.rb deleted file mode 100644 index 51d6a98..0000000 --- a/shane_fisher/oop/WNS/wizard.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative "human" - -class Wizard < Human - -def initialize - super() - @health = 50 - @int = 25 -end - -def heal - @health += 10 - self -end - -def fireball(object) - object.health -= 20 -end - -end \ No newline at end of file