small medium large xlarge

18 Feb 2016, 21:00
Nick (2 posts)

I generally struggle with coding, but this book has helped tremendously. Until I reached the things to try sections of Classes. I am unsure of this Dispatch Method and further research is not clearing it up much for me. I have made my dragon program interactive but before I go any further on it I wanted some feedback on the way i am making it interactive….

def whatToDo
   puts "What do you want to do with Norbert???"
   puts "Press 1 to Shake the Dragon"
   puts "Press 2 to Feed the Dragon"
   puts "Press 3 to Walk the dragon"
   puts "Press 4 to put the Dragon to bed"
   puts "Press 5 to toss the dragon in the air"
   puts "Press 6 to rock the dragon to sleep"
   @action = gets.chomp
    if(@action == "1")
     puts "notworking"

def shakeBabyDragon
  puts "You shake " + @name + " out of frustration."
  @shakes += 5

Is this what you had in mind for the assignment or am I missing something?

20 Feb 2016, 18:52
Chris Pine (72 posts)

Yeah, that totally works!

Personally, I think the “enter a number” thing feels a bit… computery? So I might have done something like using strings instead of numbers. So you might use 'feed' instead of 3, for example. And if they enter something you aren’t expecting (like 'feed him' or something), you could just say 'I'm sorry, but I don't understand that command. Valid commands are:' and then just list them out.

But I mean, that’s just one idea. Really, it’s up to you!

22 Feb 2016, 19:56
Nick (2 posts)

Ok, great! Thanks for response.

If you see this: How much more content does your book have compared to the online tutorial?

22 Feb 2016, 21:30
Chris Pine (72 posts)

It has some new chapters, it’s more polished, it’s updated to Ruby 2.0, and it has answers at the back of the book (and for most exercises, it has two different answers). I’d guess that it’s maybe 50% more content… but hard to say for sure.

You must be logged in to comment