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
| # in this universe, player will throw a frisbee which will track how far it flies and report progress along the way | |
| class Player | |
| attr_reader :name | |
| attr_accessor :already_had_the_ball | |
| @@player_count = 0 | |
| def initialize(name) | |
| @name = name | |
| @@player_count += 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 Drawer | |
| attr_reader :contents | |
| def initialize | |
| @contents = [] | |
| @open = true | |
| end | |
| def open |
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 Sudoku | |
| def initialize(board_string) | |
| @sudoku_board = board_string.split(//).each_slice(9).to_a | |
| p @num_zeros = board_string.split('').count('0') | |
| end | |
| def get_row(row_index, column_index) | |
| @sudoku_board[row_index] | |
| end |
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
| require_relative 'racer_utils' | |
| class RubyRacer | |
| attr_accessor :players, :length, :lane | |
| def initialize(players, length = 30) | |
| @players = players | |
| @length = length | |
| @die = Die.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
| def destroy_message(string) | |
| stop_here = string =~ /:/ #returns the index of ":" | |
| if stop_here | |
| string[0..stop_here] #returns string from 0 to 9 (which is index of ":") | |
| else | |
| string | |
| end | |
| end |
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
| # TODO: Print the elements at indices 1, 3, 5, 7, etc. on separate lines. | |
| # You should make use of Enumerable#each_with_index | |
| def print_odd_indexed_integers(array) | |
| array.each_with_index {|num, index| puts num if index % 2 != 0} | |
| end | |
| # TODO: Return the odd numbers from a list of integers. | |
| # You should make use of Enumerable#select | |
| def odd_integers(array) | |
| array.select {|num| num.odd?} |
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 pig_latin(word) | |
| word.downcase! | |
| word_arr = word.split('') | |
| until word_arr[0] == "a" || word_arr[0] == "e" || word_arr[0] == "i" || word_arr[0] == "o" || word_arr[0] == "u" || word_arr[0] == "y" | |
| f = word_arr.shift | |
| word_arr.push(f) | |
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 old_numerals(number) | |
| (number / 1000).times do print "M" end | |
| five_hundred = number % 1000 | |
| #puts five_hundred | |
| (five_hundred / 500).times do print "D" end | |
| one_hundred = five_hundred % 500 | |
| #puts one_hundred |
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
| puts "enter some words" | |
| words = gets.chomp.split.sort! | |
| puts "Congratulations! Your dictionary has #{words.length} words" | |
| words.each do |x| | |
| puts x | |
| end | |
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 deaf_grandma(state = true, greeting = true, steps = 0) | |
| if steps == 2 | |
| puts "Bye dear" | |
| state = false | |
| end | |
| puts "Hello, little boy." if greeting == true | |
| if state | |
| user_input = gets.chomp | |
| if user_input == "I love ya, Grandma, but I've got to go." | |
| puts "Bye, dear." |