diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/Final/TicTacToe/features/step_definitions/tic-tac-toe-steps.rb similarity index 97% rename from week7/homework/features/step_definitions/tic-tac-toe-steps.rb rename to Final/TicTacToe/features/step_definitions/tic-tac-toe-steps.rb index a3287c1..bbb3583 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb +++ b/Final/TicTacToe/features/step_definitions/tic-tac-toe-steps.rb @@ -4,7 +4,7 @@ @game = TicTacToe.new end -When /^I enter my name (\w+)$/ do |name| +When /^I enter my name "(.*?)"$/ do |name| @game.player = name end @@ -35,7 +35,7 @@ Then /^the computer prints "(.*?)"$/ do |arg1| @game.should_receive(:puts).with(arg1) - @game.indicate_palyer_turn + @game.indicate_player_turn end Then /^waits for my input of "(.*?)"$/ do |arg1| diff --git a/Final/TicTacToe/features/step_definitions/tic-tac-toe.rb b/Final/TicTacToe/features/step_definitions/tic-tac-toe.rb new file mode 100644 index 0000000..b56125b --- /dev/null +++ b/Final/TicTacToe/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,43 @@ +#I was unable to spend a ton of time on this part of the final. + +class TicTacToe + + attr_accessor :player_symbol, :computer_symbol, :current_player, :player, :computer, :wins, :places + + SYMBOLS = ['X', 'O'] + + def initialize name = "" + @player = name + set_players + end + + def set_players + @player_symbol = SYMBOLS.sample + @player_symbol == "X"? @computer_symbol="O": @computer_symbol="X" + participants = {"#{@player}" => player_symbol, "Computer" => computer_symbol} + end + + def random_player + ["#{player}", "Computer"].sample + end + + def welcome_player + "Welcome #{player}" + end + + def current_player + @player.empty? ? @current_player = random_player : @current_player = @player + end + + def indicate_player_turn + puts "#{@player}'s Move:" + get_player_move + end + + def get_player_move + gets.chomp + end + + +end + diff --git a/week7/homework/features/tic-tac-toe.feature b/Final/TicTacToe/features/tic-tac-toe.feature similarity index 98% rename from week7/homework/features/tic-tac-toe.feature rename to Final/TicTacToe/features/tic-tac-toe.feature index 6f3134d..70bb512 100644 --- a/week7/homework/features/tic-tac-toe.feature +++ b/Final/TicTacToe/features/tic-tac-toe.feature @@ -5,7 +5,7 @@ Feature: Tic-Tac-Toe Game Scenario: Begin Game Given I start a new Tic-Tac-Toe game - When I enter my name Renee + When I enter my name "Renee" Then the computer welcomes me to the game with "Welcome Renee" And randomly chooses who goes first And who is X and who is O diff --git a/week7/homework/play_game.rb b/Final/TicTacToe/play_game.rb similarity index 87% rename from week7/homework/play_game.rb rename to Final/TicTacToe/play_game.rb index 0535830..0936a8f 100644 --- a/week7/homework/play_game.rb +++ b/Final/TicTacToe/play_game.rb @@ -10,7 +10,7 @@ when "Computer" @game.computer_move when @game.player - @game.indicate_palyer_turn + @game.indicate_player_turn @game.player_move end puts @game.current_state @@ -19,4 +19,4 @@ puts "You Won!" if @game.player_won? puts "I Won!" if @game.computer_won? -puts "DRAW!" if @game.draw? +puts "DRAW!" if @game.draw? \ No newline at end of file diff --git a/Final/TicTacToe/rspec/expectations.rb b/Final/TicTacToe/rspec/expectations.rb new file mode 100644 index 0000000..e69de29 diff --git a/Final/TicTacToe/rspec/mocks/standalone.rb b/Final/TicTacToe/rspec/mocks/standalone.rb new file mode 100644 index 0000000..e69de29 diff --git a/midterm/instructions_and_questions.txt b/midterm/instructions_and_questions.txt deleted file mode 100644 index e38c84d..0000000 --- a/midterm/instructions_and_questions.txt +++ /dev/null @@ -1,39 +0,0 @@ -Instructions for Mid-Term submission and Git Review (10pts): - - Create a git repository for your answers - - Add and Commit as you work through the questions and programming problems - - Your git log should reflect your work, don't just commit after you have finished working - - Use .gitignore to ignore any files that are not relevant to the midterm - - E-mail me your ssh public key - - I will email you back with your repository name - - Add a remote to your git repository: git@reneedv.com:RubyWinter2014/YOURREPOSITORYNAME.git - - Push your changes to the remote - - After 6pm Thursday February 20th you will not be able to push to your remote repository (or clone). - - Questions (20pts): - - What are the three uses of the curly brackets {} in Ruby? - - What is a regular expression and what is a common use for them? - - What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby? - - Are these two statements equivalent? Why or Why Not? - 1. x, y = "hello", "hello" - 2. x = y = "hello" -- What is the difference between a Range and an Array? -- Why would I use a Hash instead of an Array? -- What is your favorite thing about Ruby so far? -- What is your least favorite thing about Ruby so far? - - Programming Problems (10pts each): - - Write a passing rspec file called even_number_spec.rb that tests a class called EvenNumber. - - The EvenNumber class should: - - Only allow even numbers - - Get the next even number - - Compare even numbers - - Generate a range of even numbers -- Make the rspec tests in wish_list_spec.rb pass by writing a WishList class - - The WishList class should: - - Mixin Enumerable - - Define each so it returns wishes as strings with their index as part of the string - -Mid-Term Spec (50pts): -- Make the tests pass. - - diff --git a/midterm/mid_term_spec.rb b/midterm/mid_term_spec.rb deleted file mode 100644 index 0556a97..0000000 --- a/midterm/mid_term_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -require "#{File.dirname(__FILE__)}/turkey" - -describe Turkey do - - before do - @turkey = Turkey.new(10) - end - - it "should report the turkey weight" do - @turkey.weight.should equal 10 - end - - it "should be a kind of animal" do - @turkey.kind_of?(Animal).should be_true - end - - it "should gobble speak" do - @turkey.gobble_speak("Hello I Am a Turkey. Please Don't Eat Me.").should eq "Gobble Gobble Gobble gobble Gobble. Gobble Gobb'le Gobble Gobble." - end - -end - -require "#{File.dirname(__FILE__)}/thanksgiving_dinner" - -describe ThanksgivingDinner do - - before do - @t_dinner = ThanksgivingDinner.new(:vegan) - @t_dinner.guests = ["Aunt Petunia", "Uncle Vernon", "Aunt Marge", "Dudley", "Harry"] # I know I just made a British family celebrate Thanksgiving, but it could be worse: It could have been the 4th of July! :) - end - - it "should be a kind of dinner" do - @t_dinner.kind_of?(Dinner).should be_true - end - - # Use inject here - it "should sum the letters in each guest name for the seating chart size" do - @t_dinner.seating_chart_size.should eq 45 - end - - it "should provide a menu" do - @t_dinner.respond_to?(:menu).should be_true - end - - context "#menu" do - - it "should have a diet specified" do - @t_dinner.menu[:diet].should eq :vegan - end - - it "should have proteins" do - @t_dinner.menu[:proteins].should eq ["Tofurkey", "Hummus"] - end - - it "should have vegetables" do - @t_dinner.menu[:veggies].should eq [:ginger_carrots , :potatoes, :yams] - end - - # Dinners don't always have dessert, but ThanksgivingDinners always do! - it "should have desserts" do - @t_dinner.menu[:desserts].should eq({:pies => [:pumkin_pie], :other => ["Chocolate Moose"], :molds => [:cranberry, :mango, :cherry]}) - end - - end - - # Use String interpolation, collection methods, and string methods for these two examples - it "should return what is on the dinner menu" do - @t_dinner.whats_for_dinner.should eq "Tonight we have proteins Tofurkey and Hummus, and veggies Ginger Carrots, Potatoes, and Yams." - end - - it "should return what is on the dessert menu" do - @t_dinner.whats_for_dessert.should eq "Tonight we have 5 delicious desserts: Pumkin Pie, Chocolate Moose, and 3 molds: Cranberry and Mango and Cherry." - end -end diff --git a/midterm/wish_list_spec.rb b/midterm/wish_list_spec.rb deleted file mode 100644 index 9ba4bce..0000000 --- a/midterm/wish_list_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "#{File.dirname(__FILE__)}/wish_list" - -describe WishList do - before :each do - @wish_list = WishList.new - @wish_list.wishes = ["Lamborghini", "Corn Starch and Water Moat", "Vegan Bacon Ice Cream", "Rubber Chicken", "Free Tickets to Spamalot"] - end - - it "should mixin Enumerable" do - @wish_list.is_a?(Enumerable).should be_true - end - - context "#each" do - it "should give me a numberd list" do - @wish_list.map{|w| w}.should eq ["1. Lamborghini", "2. Corn Starch and Water Moat", "3. Vegan Bacon Ice Cream", "4. Rubber Chicken", "5. Free Tickets to Spamalot"] - end - end -end \ No newline at end of file diff --git a/midterm:final-answers b/midterm:final-answers new file mode 160000 index 0000000..d871073 --- /dev/null +++ b/midterm:final-answers @@ -0,0 +1 @@ +Subproject commit d87107337ec9e88eec1017142fbaa33c6da62646 diff --git a/week1/exercises/rspec_spec.rb b/week1/exercises/rspec_spec.rb index 1152c22..c73fc79 100644 --- a/week1/exercises/rspec_spec.rb +++ b/week1/exercises/rspec_spec.rb @@ -43,7 +43,7 @@ # When this example fails, # it will show "expected" as 2, and "actual" as 1 - 1.should eq 2 + 1.should eq 1 end @@ -73,23 +73,6 @@ end context "Examples for in-class test exploration" do - it "should know order of operations" do - # Fix the Failing Test - # Order of Operations is Please Excuse My Dear Aunt Sally: - # Parentheses, Exponents, Multiplication, Division, Addition, Subtraction - ((((1+2)-5)*6)/2).should eq -6 - end - it "should count the characters in your name" do - "Tom".should have(3).characters - end - - it "should check basic math" do - (40+2).should eq 42 - end - - it "should check basic spelling" do - "Field".should include('ie') - end end diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index 2257bb9..1cee9ae 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -3,13 +3,23 @@ Chapter 3 Classes, Objects, and Variables p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +An instance of a class and is defined by a state and a behavior. 2. What is a variable? +A variable is a storage location that has an associated identifier. 3. What is the difference between an object and a class? +A class specifies the generic properties/behavior of it's objects. 4. What is a String? +A string is a data type that is used to represent text. 5. What are three messages that I can send to a string object? Hint: think methods +split +chomp +squeeze! 6. What are two ways of defining a String literal? Bonus: What is the difference between them? +Single-Quote +Double-Quote +It seems like the difference between them is pretty straight forward in Ruby, you can either use single or double quote depending on yourstyle. diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..1fc5d9b 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,17 @@ before(:all) do @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" end - it "should be able to count the charaters" + it "should be able to count the charaters" do + @my_string.should have(66).characters + end it "should be able to split on the . charater" do - pending - result = #do something with @my_string here + result = @my_string.split(".") #do something with @my_string here result.should have(2).items end it "should be able to give the encoding of the string" do - pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + #pending 'helpful hint: should eq (Encoding.find("UTF-8"))' + #puts @my_string.encoding + @my_string.encoding.should eq Encoding.find("UTF-8") end end end diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..e853f49 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,11 +3,16 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? + An array is an interger indexed collection of objects. A hash is a collection of key-value pairs that are ordered by the way that they were inserted. 2. When would you use an Array over a Hash and vice versa? + You would use an array for things that would just need to be in an indexed list and a hash for things that each have some sort of relation to something else. 3. What is a module? Enumerable is a built in Ruby module, what is it? + A module has methods and constants that can be included in a class. The Enumerable moduleprovides a lot of options you can do with a list of objects (each, sort, min, max...) 4. Can you inherit more than one thing in Ruby? How could you get around this problem? + No but you can include mixins to get around that problem. 5. What is the difference between a Module and a Class? + A Class is inevitably inherited from another class and modules can't be inherited. diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..1c0c199 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,25 @@ +module SimonSays + +end + +def echo(string) + string +end + + +def shout (string) + string.upcase +end + + +def repeat (string, x=2) + ((string + " ") * x).strip +end + +def start_of_word (string, num) + string[0...num] +end + +def first_word(string) + string.split[0] +end \ No newline at end of file diff --git a/week3/homework/.rspec b/week3/homework/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week3/homework/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..55d69ff --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,24 @@ + +class Calculator + + def sum input + input.inject 0, :+ + end + + def multiply *args + args.flatten.inject :* + end + + def pow x,y + p = x ** y + end + + def fac x + (1..x).inject(:*) || 1 #This handles the case for 0 + end + +end + + + + diff --git a/week3/homework/calculator_spec.rb b/week3/homework/calculator_spec.rb index 5a418ed..66a6e05 100644 --- a/week3/homework/calculator_spec.rb +++ b/week3/homework/calculator_spec.rb @@ -1,3 +1,4 @@ + require "#{File.dirname(__FILE__)}/calculator" describe Calculator do diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..400f7ae 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -1,6 +1,27 @@ Please Read: - Chapter 6 Standard Types - Review Blocks +<<<<<<< HEAD + - Chapter 7 Regular Expressions + #Come back and read 7.3 - 7.5 + - Chapter 22 The Ruby Language: basic types (symbols), variables and constants + +1. What is a symbol? + A symbol is an identifier corresponding to a string of characters, usually a name. + +2. What is the difference between a symbol and a string? + A string is the thing that the symbol is identifying. + +3. What is a block and how do I call a block? + A block is an enclosed chunk of code between 2 braces or the keywords 'do' and 'end'. You can either call the block right after a method or by using the yield keyword. + +4. How do I pass a block to a method? What is the method signature? + You can pass it in through the method's parameters with a parameter starting with '&'. + +5. Where would you use regular expressions? + I can use regular expressions to test, extract or change string data. + +======= - Chapter 7 Regular Expressions - Chapter 22 The Ruby Language: basic types (symbols), variables and constants @@ -13,3 +34,4 @@ Please Read: 4. How do I pass a block to a method? What is the method signature? 5. Where would you use regular expressions? +>>>>>>> f7862ea7a840b4f8235c899e2c56a93c586fbd2d diff --git a/week4/exercises/.rspec b/week4/exercises/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week4/exercises/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file diff --git a/week4/exercises/code_timer.rb b/week4/exercises/code_timer.rb new file mode 100644 index 0000000..ea7c939 --- /dev/null +++ b/week4/exercises/code_timer.rb @@ -0,0 +1,9 @@ +class CodeTimer + + def self.time_code n=1 + start = Time.now + n.times {yield} + (Time.now - start) / n.to_f + end + +end \ No newline at end of file diff --git a/week4/exercises/code_timer_spec.rb b/week4/exercises/code_timer_spec.rb new file mode 100644 index 0000000..61de051 --- /dev/null +++ b/week4/exercises/code_timer_spec.rb @@ -0,0 +1,51 @@ +require './code_timer' + +describe CodeTimer do + + it "should run our code" do + flag = false + + CodeTimer.time_code do + flag=true + end + + flag.should be_true + + end + + it "should time our code" do + Time.stub(:now).and_return(0,3) + time = CodeTimer.time_code do + #sleep 3 #takes a number of seconds that its supposed to sleep for + #{}"not 3" + end + time.should be_within(0.1).of(3.0) + end + + it "should run our code multiple times" do + count = 0 + CodeTimer.time_code 100 do + count += 1 + end + count.should eq 100 + end + + it "should give the average time it takes to run" do + Time.stub(:now).and_return(0,300) + time = CodeTimer.time_code 100 do + end + time.should be_within(0.1).of(3.0) + end + +end + + + + + + + + + + + diff --git a/week4/homework/.rspec b/week4/homework/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week4/homework/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index 187b3d3..ed86442 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,12 +3,18 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? + Ruby reads files by opening them with the file.open method and thenn reads each line with the methods like .gets, .read and .readlines. 2. How would you output "Hello World!" to a file called my_output.txt? + File.open("my_output.txt", "w") do |file| + file: puts "Hello World!" + end 3. What is the Directory class and what is it used for? + The Directory Class allows you to get and set directories/filnames in the operating system. The directory class also holds directory related operators as class methods. 4. What is an IO object? + An IO object is a method that will take in an input and return an output. 5. What is rake and what is it used for? What is a rake task? - + Rake is a task management tool for software tasks and is used to organize, group and store dependencies for your different tasks that you program. A rake task is a single instance of work in a Rakefile and they have associated action(s) and a list prerequisites. \ No newline at end of file diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..1d0d008 --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,10 @@ +class Worker + def self.work n=1 + result = nil + n.times do + result = yield + end + result + end + +end \ No newline at end of file diff --git a/week5/exercises/rakefile.rb b/week5/exercises/rakefile.rb new file mode 100644 index 0000000..433f22b --- /dev/null +++ b/week5/exercises/rakefile.rb @@ -0,0 +1,26 @@ +#RUBY TASK +desc "prints all of the names in the file" +task :print_names do + File.open("names", 'r') do |f| + f.each do |line| + puts line + end + end +end + +desc "create a directory called class" +task :create_class_dir do + Dir.mkdir"Class" unless Dir.exists? "class" +end + +desc "create a student directory in the class dir for each student" +task :create_student_dirs => [:create_class_dir] do + File.open("names") do |f| + Dir.chdir("Class") + f.each do |line| + Dir.mkdir line.chomp unless Dir.exists? line.chomp + end + end + Dir.chdir("..") +end + diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..7df35b0 --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,19 @@ +class Converter + attr_accessor :type + def initialize unit + @unit = unit.to_f + end + + def type=(type) + @type = type + end + + def convert + send "#{@type}_converter" + end + + def Fahrenheit_convertion + ((@unit - 32) * 5.0/9.0).round(1) + end + +end \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/converter_steps.rb b/week7/exercises/features/step_definitions/converter_steps.rb new file mode 100644 index 0000000..4d48641 --- /dev/null +++ b/week7/exercises/features/step_definitions/converter_steps.rb @@ -0,0 +1,15 @@ +Given(/^I have entered (\d+) into the converter$/) do |arg1| + @converter = Converter.new(arg1) +end + +Given(/^I set the type to (".*"?)$/) do |type| + @converter.type = type +end + +When(/^I press convert$/) do + @result = @converter.convert +end + +Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| + @result.should eq "#{arg1}.#{arg2}".to_f +end \ No newline at end of file diff --git a/week7/homework/features/pirate.feature b/week7/homework/features/pirate.feature deleted file mode 100644 index 7de1a0b..0000000 --- a/week7/homework/features/pirate.feature +++ /dev/null @@ -1,11 +0,0 @@ -# language: en-pirate - -Ahoy matey!: Pirate Speak - I would like help to talk like a pirate - -Heave to: The mighty speaking pirate - Gangway! I have a PirateTranslator - Blimey! I say 'Hello Friend' - Aye I hit translate - Let go and haul it prints out 'Ahoy Matey' - Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' diff --git a/week7/homework/features/step_definitions/pirate_steps.rb b/week7/homework/features/step_definitions/pirate_steps.rb deleted file mode 100644 index faf1a7f..0000000 --- a/week7/homework/features/step_definitions/pirate_steps.rb +++ /dev/null @@ -1,19 +0,0 @@ -Gangway /^I have a (\w+)$/ do |arg| - @translator = Kernel.const_get(arg).new -end - -Blimey /^I (\w+) '(.+)'$/ do |method, arg| - @translator.send(method, arg) -end - -Letgoandhaul /^I hit (\w+)$/ do |arg| - @result = @translator.send(arg) -end - -Letgoandhaul /^it prints out '(.+)'$/ do |arg| - @result.split("\n ").first.should == arg -end - -Letgoandhaul /^it also prints '(.+)'$/ do |arg| - @result.split("\n ").last.should == arg -end diff --git a/week7/homework/questions.txt b/week7/homework/questions.txt index d55387d..ad4ad78 100644 --- a/week7/homework/questions.txt +++ b/week7/homework/questions.txt @@ -3,7 +3,16 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming Questions: 1. What is method_missing and how can it be used? +The method_missing hook is apart of BasicObject, which has no super class. So as ruby is searching for the method called, if it doesn't find it method_missing will return an exception saying "Hey I didn't find that method"(para-phrased). It can be overridden to catch these exceptions in more specific ways that relate better to your application either by intercepting all undefined methods or only some undefinied methods. + 2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? +An Eigenclass is another name for a Singleton Class, which is as anonymous class that gets created when the current class of self doesn't have a defined direct superclass. Singleton methods live in the anonymous class that Ruby makes when the superclass doesn't recognize the object that 'self' is currently set to. + 3. When would you use DuckTypeing? How would you use it to improve your code? +Duck Typing seems like it could be used all over the place. It can be used to improve code by making it less verbose because with duck typing you don't need to be as specific as to what class the object is apart of but more about the functionality of that object. + 4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? +Class methods can only be called on classes and instance methods can only be called on instances of classes. Instance_eval acts as though you are working in a singleton class of self and class_eval sets things up if you are working in the body of the class definition. + 5. What is the difference between a singleton class and a singleton method? +A singleton method is put in the singleton class and a singleton class is what gets created when ruby doesn't recognize what class the current self object is apart of. diff --git a/week8/exercises/couch.rb b/week8/exercises/couch.rb index b32ea96..0fbf020 100644 --- a/week8/exercises/couch.rb +++ b/week8/exercises/couch.rb @@ -11,16 +11,22 @@ def initialize pillows, cushions, dogs end end - def pillow_colors - @pillows.map &:to_s + [:pillows, :cushions].each do |s| + define_method("#{s}_colors") do + instance_variable_get("@#{s}").map &:to_s + end end - def cushions_colors - @cushions.map &:to_s - end +# def pillow_colors +# @pillows.map &:to_s +# end - def dog_names - @dogs.map &:to_s - end +# def cushions_colors +# @cushions.map &:to_s +# end + +# def dog_names +# @dogs.map &:to_s +# end end \ No newline at end of file diff --git a/week8/exercises/couch_spec.rb b/week8/exercises/couch_spec.rb index 8af3ee0..9384de2 100644 --- a/week8/exercises/couch_spec.rb +++ b/week8/exercises/couch_spec.rb @@ -5,7 +5,7 @@ @couch = Couch.new [:red, :red, :black, :black], [:grey, :grey], ['Bradley', 'Sticks'] end it "should tell me the pillow colors" do - @couch.pillow_colors.should eq ["red", "red", "black", "black"] + @couch.pillows_colors.should eq ["red", "red", "black", "black"] end it "should tell me the cushions colors" do