"You must type each of these exercises in, manually. If you copy and paste, you might as well just not even do them. The point of these exercises is to train your hands, your brain, and your mind in how to read, write, and see code. If you copy-paste, you are cheating yourself out of the effectiveness of the lessons."
Having said that, you could clone the git repository, remove the "linenos" option and run the Jekyll site locally.
But, I was having a problem with exercise 4 and so copy/pasted it from the webpage (removed line numbers with TextMate's vertical selection easily enough). Received the same error when trying to run it as I did when I typed it myself:
ex4.rb:10:in `+': can't convert Fixnum into String (TypeError) from ex4.rb:10:in `<main>'
I'm not familiar enough with Ruby to understand why it's doing that... my googling shows similar ruby tutorials with that format, but one site I found suggested using #{variable_name} instead of the " + variable_name + " and that worked just fine for me.
Is this a real error in the book or something weird going on with my computer (OS X Lion w/ Ruby 1.9.2 installed)?
Great book, by the way.
In hindsight, I probably should have used "Hello #{name}" style string interpolation in all of the examples since thats the idiomatic way of doing things.
I was trying to expose the newcomer to multiple ways of manipulating and concatenating strings, but since the aforementioned way is almost always best, I should stick to that.
This seems to explain it: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/...
puts "There are #{cars} cars available."
But, yeah, complete Ruby noob here as well so I don't really know what's wrong.
Yes, this will throw an error in Ruby because of line 1:
>1 cars = 100
Ruby does not allow the mixing of integers and strings. So, as mentioned, you can invoke the .to_s method. Or you can interpolate the variables as you have done so with #{cars} inside double quotes.