On Tue, Dec 03, 2002 at 08:52:25PM +0900, Martin DeMello wrote:
> Daniel Carrera <dcarrera / math.umd.edu> wrote:
> > I am actually thinking of trying to make a tutorial for precisely this
> > purpose.  I'm just getting started, so there's nothing really there yet.
> > But you can look at what I here:
> > 
> > www.math.umd.edu/~dcarrera/ruby/index.html
> 
> Perhaps you should introduce IRB right at the beginning, so that people
> can play with more immediate examples. (On the other hand, the
> ubiquitous return value could be confusing - how hard would a beginner's
> mode that outputs something only when asked to be to hack up?).
> 
> One suggestion - have an 'Objects' section *before* 'Variables' - start
> with defining an object (*don't* introduce the term 'object oriented
> programming', or classes - just make it seem like an object is the
> natural unit of data storage), and then segue into variables.
> 
> Feel free to use as much or as little of the following as you wish:
> 
> <<EOF
> 
> What is an Object?
> 
[snip]
> puts 5.0/3 # -> 1.666666667
> 
> !Note: Each operator is actually several different methods, depending on
> the type of its left hand operand. The two we just saw are, in full,
> Integer#/ and Float#/. This is sometimes referred to as 'operator
> overloading'.

Isn't it rather just an example of polymorphism (dynamic dispatch based
on the type of the receiver)? Anyway I don't think these terms need to be
introduced in a tutorial.

> Thanks to overloading, we can use the arithmetic operators with objects
> of other types too, For instance, we have String#+ and String#* as shown:
> 
> puts "Hello" + "World" # -> HelloWorld
> puts "foo" * 3 # -> foofoofoo
> 
> And similarly for Arrays:
> 
> p [1,2,3] + [4,5] # -> [1,2,3,4,5]
> p ["a", "b"] * 3 # -> ["a", "b", "a", "b", "a", "n"]
> 
> !Note: We have introduced the 'p' function - p 'pretty prints' complex
> objects like Arrays. To see the difference between 'puts' and 'p', try
> the following:
> puts [1,2,3]
> p [1,2,3]
> 
[...]


-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Sigh.  I like to think it's just the Linux people who want to be on
the "leading edge" so bad they walk right off the precipice.
	-- Craig E. Groeschel