Idea: Ruby Tutorial For Newbies

S

simonh

Hello all. I am learning to program with ruby but I'm struggling to
find a really good tutorial or book aimed at beginners. The pickaxe 2nd
ed. is an incredible book but can be a little intimidating for
beginners. Many of the other books cover ruby 1.6. The available
tutorials I've found either don't go far enough or spend too long
telling stories (sorry Why)! Anyway, I think it would be beneficial to
have a set of tutorials in the form of dialogues similar to the
artcompsci project:

link: http://www.artcompsci.org/kali/development.html

but aimed at non mathematical problems. Here is a sample of what I am
proposing: (bear in mind I am a newby too). I think it would be better
for a ruby guru to write the dialogues.

-----------------------------------------------------------------------------------------------------------------------------------
T- Teacher
S- Student


T: Ok lets get started. Here is a 'hello world' program. This is
usually the first program a student writes in any programming language.
All it does is print the phrase Hello World onto the screen.

puts "Hello World"

Hello world


T: How do you think this program works?


S: It looks to me like the word puts is a command. The phrase Hello
World is the text that the command should print out. I'm not sure why
the phrase is quoted though. The quotes don't appear on the screen.

T: Well spotted. The phrase Hello World is what we call a String. We
identify Strings by enclosing text within quotation marks. We use
single ( ' ) and double ( " ) quotes in Ruby. We'll come to the
differences between using single or double quotes later on. You
suggested that puts was a command. In fact it's a method. Methods are a
core concept of Ruby so fix that in your mind. Here is a description of
what the program is doing: The method puts receives the String Hello
World as its argument. puts is a method defined in the Kernel module.
We'll come to that later as well.

S: Does it matter if puts is upper or lowercase?

T: Try it out

S: Puts "Hello World"
beginner.rb:1: undefined method `Puts' for main:Object (NoMethodError)
Exit code: 1

S: Obviously it doesn't work. An error message has been printed.

T: You should get used to reading error messages straight away. Ruby is
telling us that the error occurred in line 1 beginner.rb:1 it then
tells us the error. We have not defined a method 'Puts' for main:Object
In Ruby methods should always be lowercase. Classes, Modules and
Constants are uppercase. For now don't worry about any of these new
terms. We will cover them before long.

S: It seems there is a lot of stuff we will be covering later on!

T: Yes I know. Its quite hard to know where to start with someone who
has no programming experience. My plan is to introduce you to some
basic Ruby and then explain things at the right time. I promise you'll
understand all of these concepts before long.

S: Ok, I'll take your word for it. What's next?

T: Rather that use the method puts we can use print instead

print "Hello World"
Hello World

T: The difference is that puts will print the string and insert a
newline character where as print will not. See the cursor is now on the
same line? Change print to puts and see where the cursor is then.

S: Oh right. Yep I see what you mean.

T: Try this

puts "Hello World"
puts "I am learning Ruby!"
Hello World
I am learning Ruby!

T: Now do the same thing with print

print "Hello World"
print "I am learning Ruby!"
 
S

simonh

Maybe people could volunteer to do a chapter.

The Basics
Classes and Modules
Variables
Ruby Way
Regular Expressions
IRB
etc


The possibilities are endless. The entire standard library could be
covered?
 
A

anne001

I've found either don't go far enough or spend too long
telling stories (sorry Why)

What you are proposing seems to me to have too many words, and to
suggest something so basic, it won't go anywhere fast.
 
A

anne001

I've found either don't go far enough or spend too long
telling stories (sorry Why)

What you are proposing seems to me to have too many words, and to
suggest something so basic, it won't go anywhere fast.
 
S

simonh

thanks for the replies everyone. had a new idea - the pickaxe
companion. the new idea is to expand on the ideas from that famous book
with more concrete, real world examples.

richhg12hs - yes seen that tutorial. not the updated version though. it
looks very good. i'm going to read through it now
 
S

simonh

i think i'd better buy 'learn to program' by chris pine. this might be
just what i need
 
A

Adam Sanderson

What about http://tryruby.hobix.com/ ? It actually works the way you
describe for the most part. It's a lot more down to earth than say the
Poignant Guide ;) The scripts Why uses are just basic htm with some
class markup, so anyone can make new ones.
.adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top