Learning to Program in Ruby

http://rcm.amazon.com/e/cm?t=ignequil-20&o=1&p=8&l=bpl&asins=1934356360&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr
For quite a while I’ve been saying I wanted to learn to program in Ruby.  Actually, the first programming language I thought I’d learn was Python, but working for a start-up that uses Ruby on Rails, Python doesn’t make a lot of sense.  In any event, I’m glad to say that, despite the loneliness of having my wife and kids gone on vacation visiting family in Brazil for more than a month, this has been an excellent opportunity for me to devote time to Ruby.  I’m finally getting somewhere!

There are a lot of good, free online books and tutorials about Ruby, but the one I’ve been using is “Learn to Program” by Chris Pine.  This tutorial can be accessed for free online or you can obtain a hard copy from Amazon.com.  This tutorial assumes no knowledge of programming at all, starting the aspiring programmer out at the most basic information.  For me, this was perfect.

One problem I noticed was that when I went looking for help online with some of the exercises, the answers given by more advanced programmers utilized techniques way ahead of what the book itself provides.  All of the exercises given in the book can in fact be done with the information provided up to that point, so if you do go looking for help online in forums and elsewhere, be careful to look for pointers that use what you should know already from the book.

Just for fun, here’s a little program I cobbled together from my limited understanding of Ruby as I was going through the section on loops.  It’s based on the argument between John Bender and Principal Vernon in The Breakfast Club.


#famous scene from The Breakfast Club
#just the principal's part will be correct

puts 'You're not fooling anyone, Bender. The next screw that falls out will be you.'

answer = gets.chomp

puts 'What was that?'

puts 'I said, ' + answer + '.'

answer = ''

while answer != 'stop'

puts 'You just bought yourself another Saturday.'

answer = gets.chomp

puts 'You just bought one more.'

answer = gets.chomp

puts 'We'll keep going. You want another one? Just say the word say it. Instead of going to prison you'll come here. Are you through?'

answer = gets.chomp

if answer.downcase == 'yes'
yes = 'stop'
puts 'Fine, now everyone shut up. I'm going back to my office.'
Process.exit
else

puts 'I'm doing society a favor.'

answer = gets.chomp

puts 'That's another one right now! I've got you for the rest of your natural born life if you don't watch your step. You want another one?'

answer = gets.chomp

if answer.downcase == 'no'
no = 'stop'
puts 'Fine, now everyone shut up. I'm going back to my office.'
Process.exit
else
puts 'You got it! You got another one right there! That's another one pal!'

puts 'You through?'

answer = gets.chomp

if answer.downcase == 'yes'
yes = 'stop'
puts 'Fine, now everyone shut up. I'm going back to my office.'
Process.exit
else
puts 'Good! You got one more right there!'

answer = gets.chomp

puts 'Another! You through?'

answer = gets.chomp

if answer.downcase == 'yes'
yes = 'stop'
puts 'Fine, now everyone shut up. I'm going back to my office.'
else
puts 'Let's just do this again'

end
end
end

end

end

Below is the first of a video series about programming in Ruby, though not based on the book I’ve reviewed here.  I provide it simply to provide a basic intro to the language, though of course if you find the series helpful, by all means follow up with the others in the series.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s