A ruby course

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the slides have finished I will start with a free experimentation phase based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct the language and if somebody comes up with a great example or exercise I would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

Regards,

Brian

···

--
Brian Schröder
http://ruby.brian-schroeder.de/

The presentation is looking pretty good. One thing I did notice, on page 19 and 20, the comments do not reflect the code. You talk about yield, but use a passed block.

Cover slide looks good! :wink:

James Edward Gray II

···

On Oct 4, 2004, at 12:17 PM, Brian Schröder wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby this week, and I've created some slides to aid me with this.

Brian Schröder wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby
this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and
also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger
part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the
slides have finished I will start with a free experimentation phase
based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct
the language and if somebody comes up with a great example or exercise I
would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

This is great! Can I add your slides to the WhyRuby? repository
(http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?

Curt

[Brian Schröder <ruby@brian-schroeder.de>, 2004-10-04 19.17 CEST]

It would be great if some of you could look at the slides and correct
the language and if somebody comes up with a great example or exercise I
would also be glad for comments.

Page 7: Ruby follow the principle of least surprise POTS
  should be "follows" and "POLS"

Page 8: Function -> Functions
  maybe brackets should be omitted on line 7?
  maybe you should mark what you type from the program's output? I
thought "hello world" was an example of function calling without brackets :slight_smile:

Page 9: (I don't follow "often a variable will become a method" (??))

Page 12: ruby -> ruby's (?)

Page 14: in "First program": you don't follow your own advice from page 11
("-w" switch).

Page 15: "entrys" -> "entries" (?)

Page 18: "skope" -> "scope"

Page 19: see page 20

Page 20: Is it a good idea to use 'f' both as method name and the name of
the method's main variable?

Page 21: see page 22

Page 22: similar as above (parameter name 'call' in example of Proc#call)

Page 23: ... I got tired :wink:

Nice course. Good luck.

p4. Output doesn't fit on page (what I'll call "output overflow").

p7. Output overflow, plu inappropriate full justification of code.

BTW: why can I see "this=is=the=result;nil" all over the place? Yuck.

p8. s/follow/follows/ s/shure/sure/

p10. s/the class/the class./

p12. s/vi/vim/ :slight_smile:

p13. Prefer a typewriter (monospace) font. *Much* prefer. This goes
     for most, if not all, code and output. But *especially* on this
     page :slight_smile:

p14. s/into ri/into irb/

I'll just pause to say that this is a very very very good set of
slides, and attractively presented. Well done.

p16. s/can be used/can be used.../ s/but beware/...but beware/

p19. "map do ... end" reads badly to me, as a matter of style, because
     map is not *doing* anything; it's generating a value. So I
     prefer to read "map { ... }". I realise you're probably trying
     to keep it simple.

p20. You've got room; format line 9 onto three lines for clarity.

p21. Oh, I see. You may not have room. Consider it anyway.

p22. Boring example. Think of something that generates an interesting
     result.

p23. s/instanciated/instantiated/ s/n times/n times./
     s/longest_string ,/longest_string,/
     s/shortest_string/shortest_string,/

p24. s/"/""/

p28. Good exercise. With the Fibonacci generator class, give example
     usage and output so students know what they're aiming for. This
     will require its own slide.

p29. s/A real application/A Real Application/ (suggestion only)

p31. s/gui/GUI/

p32. Lines 2 and 3 have inconsistent punctuation. Add a period, or
     remove one.

  (Nice example app, by the way.)

p33. Is it possible to show us a "screenshot" of the application
     before launching into improvements?

p34. As per p32.

p36. s/Re raise/Re-raise/

p36. What about plain old "rescue"? (i.e. what does it rescue by
     default?)

p37. Slight output overflow. s/running./running/ ?

p38. s/running./running/ ?

p39. Format line 8 on several lines for readability.

p42. s/clients socket/client's socket/
     s/clients-thread/the client's thread/

p43. Title case?

p44. "Accessor functions" repeated. "Modules" and "Modules
     Exercises": no other outline has this information.

p45. s/propertys/properties/
     The "Calculated Property" and "Shortcut" boxes would look better
     if their positions were reversed.

p47. s/array like/array-like/g
     s/, can be used/ can be used/g
     Slight overflow bottom right.

p48. s/christian/Christian/ (I think; I use "given name" anyway.)
     The fields and descrptions don't match!!
     s/String::split/String#split/

     Perhaps you want Person#name -> Name object, with
       Name#first and Name#last.
     Then Person#age and Person#gender to complete the exercise.

p49. s/no special/not a special/
     s/function,/function/
     This slide is confusing. You're not demonstrating the ability to
     "change classes, functions, modules at runtime".

p50. 0! == 1

p51. Good exercise. How about another?

p52. It would be good to teach extending objects, because it's core to
     Ruby, and important when understanding "class methods". But you
     can emphasise that it's advanced material, so students needn't be
     worried if they don't get it straight away. (It's not *that*
     hard to accept, anyway... :slight_smile:

p53. A comment on line 21 would help: "Includes the AntGame namespace
     to this context", or something.

p54. I can't follow this code at a (late night) glance, so I hope
     you're explaining it well in person :slight_smile:

p55. Missing exercises.

p56. Title case?

p57. Again, second-level headings in the section overview are
     inconsistent with the early style.

So close, but so tired. I'll review the rest tomorrow. This is a
*brilliant* learning/teaching resource. I'm teaching a couple of
friends Ruby at the moment, and I'll be giving this to them for
self-study.

Cheers,
Gavin

···

On Tuesday, October 5, 2004, 3:17:47 AM, Brian wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby
this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and
also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger
part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the
slides have finished I will start with a free experimentation phase
based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct
the language and if somebody comes up with a great example or exercise I
would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

Brian Schröder wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the slides have finished I will start with a free experimentation phase based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct the language and if somebody comes up with a great example or exercise I would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

Regards,

Brian

Thank you all for the great discussion and helpfull examples!

Sadly I could not use all the examples, because I have limited time in the course. But I wanted to acknowledge that people here are always full of good ideas.

Regards,

Brian

···

--
Brian Schröder
http://ruby.brian-schroeder.de/

Do you have speaker notes?

If you had 1 to 2 hours to present ruby to a group of people what do
you think would be the most important point to get across? Mind you,
you would need to spend 30- mins on syntax.
Becker

···

On Tue, 5 Oct 2004 02:32:53 +0900, James Edward Gray II <james@grayproductions.net> wrote:

On Oct 4, 2004, at 12:17 PM, Brian Schröder wrote:

> Hello List,
>
> again I ask for your help. I'm going to give a 16 hours course on ruby
> this week, and I've created some slides to aid me with this.

The presentation is looking pretty good. One thing I did notice, on
page 19 and 20, the comments do not reflect the code. You talk about
yield, but use a passed block.

Cover slide looks good! :wink:

James Edward Gray II

Ruby Quick Start by Michael Neumann
A German language presentation that introduces Ruby. The target
audience is software developers. Format:
[http://www.pureteenz.com/hentai/ hentai] PDF.

Download at [http://rubyforge.org/docman/view.php/251/94/RubyQuickStart?.tgz
RubyQuickStart?.tgz]

Does anyone have this in english?
Becker

···

On Tue, 5 Oct 2004 02:35:28 +0900, Curt Hibbs <curt@hibbs.com> wrote:

Brian Schröder wrote:
>
> Hello List,
>
> again I ask for your help. I'm going to give a 16 hours course on ruby
> this week, and I've created some slides to aid me with this.
> I have to admit that some examples might not be as bright as I wish, and
> also there are missing some exercises.
> I created the slides in english, such that they can be used by a bigger
> part of the community if need should be.
>
> The slides will not cover all that I hope to say in the course, when the
> slides have finished I will start with a free experimentation phase
> based on my ants sample implementation
> http://ruby.brian-schroeder.de/ants/
>
> It would be great if some of you could look at the slides and correct
> the language and if somebody comes up with a great example or exercise I
> would also be glad for comments.
>
> The slides are located at
> http://ruby.brian-schroeder.de/course/

This is great! Can I add your slides to the WhyRuby? repository
(http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?

Curt

I noticed a couple of typos:

  Page 8: if the situation is not ambigue
  should be: if the situation is not ambiguos

  Page 11: skript
  should be: script

Curt

Curt Hibbs wrote:

···

Brian Schröder wrote:
>
> Hello List,
>
> again I ask for your help. I'm going to give a 16 hours course on ruby
> this week, and I've created some slides to aid me with this.
> I have to admit that some examples might not be as bright as I wish, and
> also there are missing some exercises.
> I created the slides in english, such that they can be used by a bigger
> part of the community if need should be.
>
> The slides will not cover all that I hope to say in the course, when the
> slides have finished I will start with a free experimentation phase
> based on my ants sample implementation
> http://ruby.brian-schroeder.de/ants/
>
> It would be great if some of you could look at the slides and correct
> the language and if somebody comes up with a great example or exercise I
> would also be glad for comments.
>
> The slides are located at
> http://ruby.brian-schroeder.de/course/

This is great! Can I add your slides to the WhyRuby? repository
(http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?

Curt

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 9/24/2004

James Edward Gray II wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby this week, and I've created some slides to aid me with this.

The presentation is looking pretty good. One thing I did notice, on page 19 and 20, the comments do not reflect the code. You talk about yield, but use a passed block.

Cover slide looks good! :wink:

Thanks :wink: I really liked this. Even though the unetched one had a better angle of vision, but the etched ruby is geekier.

Thanks for the comments. In fact there was a problem in my makefiles, I had fixed this before but the update was not reflected. Guess I have to learn rake.

I want to link to your sides on the slides homepage to give you the credits for the image, where should I link to?

regards,

Brian

···

On Oct 4, 2004, at 12:17 PM, Brian Schröder wrote:

--
Brian Schröder
http://ruby.brian-schroeder.de/

Curt Hibbs wrote:

Brian Schröder wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby
this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and
also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger
part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the
slides have finished I will start with a free experimentation phase
based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct
the language and if somebody comes up with a great example or exercise I
would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

This is great! Can I add your slides to the WhyRuby? repository
(http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?

Curt

Shure, but the final relase will be on sunday after the course has finished.
Until then I hope the slides will expand a bit more.

Regards,

Brian

···

--
Brian Schröder
http://ruby.brian-schroeder.de/

Thanks a lot for the exhaustive list! I'm sorry that I seem to have put up slides where the formating was broken. I'm just uploading the new version. (Now including unit testing).

Regards,

Brian

Gavin Sinclair wrote:

···

On Tuesday, October 5, 2004, 3:17:47 AM, Brian wrote:

Hello List,

again I ask for your help. I'm going to give a 16 hours course on ruby
this week, and I've created some slides to aid me with this.
I have to admit that some examples might not be as bright as I wish, and
also there are missing some exercises.
I created the slides in english, such that they can be used by a bigger
part of the community if need should be.

The slides will not cover all that I hope to say in the course, when the
slides have finished I will start with a free experimentation phase based on my ants sample implementation
http://ruby.brian-schroeder.de/ants/

It would be great if some of you could look at the slides and correct
the language and if somebody comes up with a great example or exercise I
would also be glad for comments.

The slides are located at
http://ruby.brian-schroeder.de/course/

p4. Output doesn't fit on page (what I'll call "output overflow").

p7. Output overflow, plu inappropriate full justification of code.

BTW: why can I see "this=is=the=result;nil" all over the place? Yuck.

p8. s/follow/follows/ s/shure/sure/

p10. s/the class/the class./

p12. s/vi/vim/ :slight_smile:

p13. Prefer a typewriter (monospace) font. *Much* prefer. This goes
     for most, if not all, code and output. But *especially* on this
     page :slight_smile:

p14. s/into ri/into irb/

I'll just pause to say that this is a very very very good set of
slides, and attractively presented. Well done.

p16. s/can be used/can be used.../ s/but beware/...but beware/

p19. "map do ... end" reads badly to me, as a matter of style, because
     map is not *doing* anything; it's generating a value. So I
     prefer to read "map { ... }". I realise you're probably trying
     to keep it simple.

p20. You've got room; format line 9 onto three lines for clarity.

p21. Oh, I see. You may not have room. Consider it anyway.

p22. Boring example. Think of something that generates an interesting
     result.

p23. s/instanciated/instantiated/ s/n times/n times./
     s/longest_string ,/longest_string,/
     s/shortest_string/shortest_string,/

p24. s/"/""/

p28. Good exercise. With the Fibonacci generator class, give example
     usage and output so students know what they're aiming for. This
     will require its own slide.

p29. s/A real application/A Real Application/ (suggestion only)

p31. s/gui/GUI/

p32. Lines 2 and 3 have inconsistent punctuation. Add a period, or
     remove one.

  (Nice example app, by the way.)

p33. Is it possible to show us a "screenshot" of the application
     before launching into improvements?

p34. As per p32.

p36. s/Re raise/Re-raise/

p36. What about plain old "rescue"? (i.e. what does it rescue by
     default?)

p37. Slight output overflow. s/running./running/ ?

p38. s/running./running/ ?

p39. Format line 8 on several lines for readability.

p42. s/clients socket/client's socket/
     s/clients-thread/the client's thread/

p43. Title case?

p44. "Accessor functions" repeated. "Modules" and "Modules
     Exercises": no other outline has this information.

p45. s/propertys/properties/
     The "Calculated Property" and "Shortcut" boxes would look better
     if their positions were reversed.

p47. s/array like/array-like/g
     s/, can be used/ can be used/g
     Slight overflow bottom right.

p48. s/christian/Christian/ (I think; I use "given name" anyway.)
     The fields and descrptions don't match!!
     s/String::split/String#split/

     Perhaps you want Person#name -> Name object, with
       Name#first and Name#last.
     Then Person#age and Person#gender to complete the exercise.

p49. s/no special/not a special/
     s/function,/function/
     This slide is confusing. You're not demonstrating the ability to
     "change classes, functions, modules at runtime".

p50. 0! == 1

p51. Good exercise. How about another?

p52. It would be good to teach extending objects, because it's core to
     Ruby, and important when understanding "class methods". But you
     can emphasise that it's advanced material, so students needn't be
     worried if they don't get it straight away. (It's not *that*
     hard to accept, anyway... :slight_smile:

p53. A comment on line 21 would help: "Includes the AntGame namespace
     to this context", or something.

p54. I can't follow this code at a (late night) glance, so I hope
     you're explaining it well in person :slight_smile:

p55. Missing exercises.

p56. Title case?

p57. Again, second-level headings in the section overview are
     inconsistent with the early style.

So close, but so tired. I'll review the rest tomorrow. This is a
*brilliant* learning/teaching resource. I'm teaching a couple of
friends Ruby at the moment, and I'll be giving this to them for
self-study.

Cheers,
Gavin

--
Brian Schröder
http://ruby.brian-schroeder.de/

Hello Group,

I need more help.

Gavin Sinclair wrote:

p51. Good exercise. How about another?

Anybody has an idea for an exercise on extending existing classes. So far the only thing I have come up with is:

\exercise{Fibonacci II}{
   Extend \codetype{Integer} with a function fib that calculates the
   corresponding fibonacci number.}

And my creativity is at an all time low.

p52. It would be good to teach extending objects, because it's core to
     Ruby, and important when understanding "class methods". But you
     can emphasise that it's advanced material, so students needn't be
     worried if they don't get it straight away. (It's not *that*
     hard to accept, anyway... :slight_smile:

Anybody nows of a good example where it is neccessary to extend an existing object?
I have never used this feature and I don't know when to use it in a sensible way.

p55. Missing exercises.

Somebody has an idea for an exercise on using modules (as namespace and mixin?)

A big thanks so far to all the people who have reviewed the slides!

regards,

Brian

···

--
Brian Schröder
http://ruby.brian-schroeder.de/

Curt Hibbs wrote:

I noticed a couple of typos:

  Page 8: if the situation is not ambigue
  should be: if the situation is not ambiguos

Gee... there's a mistake in my correction! :frowning:

I should have said...
   should be: if the situation is not ambiguous

···

  Page 11: skript
  should be: script

Curt

Curt Hibbs wrote:
> Brian Schröder wrote:
> >
> > Hello List,
> >
> > again I ask for your help. I'm going to give a 16 hours course on ruby
> > this week, and I've created some slides to aid me with this.
> > I have to admit that some examples might not be as bright as
I wish, and
> > also there are missing some exercises.
> > I created the slides in english, such that they can be used
by a bigger
> > part of the community if need should be.
> >
> > The slides will not cover all that I hope to say in the
course, when the
> > slides have finished I will start with a free experimentation phase
> > based on my ants sample implementation
> > http://ruby.brian-schroeder.de/ants/
> >
> > It would be great if some of you could look at the slides and correct
> > the language and if somebody comes up with a great example or
exercise I
> > would also be glad for comments.
> >
> > The slides are located at
> > http://ruby.brian-schroeder.de/course/
>
> This is great! Can I add your slides to the WhyRuby? repository
> (http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?
>
> Curt
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.769 / Virus Database: 516 - Release Date: 9/24/2004
>

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.769 / Virus Database: 516 - Release Date: 9/24/2004

If you're worried about it, just include my name. Hmm, unless you want to use it as an excuse to get more people hooked on Ruby Quiz? <laughs> Seriously, the image is free. You're under no obligation. I'm glad it helped.

James Edward Gray II

···

On Oct 4, 2004, at 3:08 PM, Brian Schröder wrote:

I want to link to your sides on the slides homepage to give you the credits for the image, where should I link to?

Brian Schröder wrote:

Curt Hibbs wrote:
> Brian Schröder wrote:
>
>>Hello List,
>>
>>again I ask for your help. I'm going to give a 16 hours course on ruby
>>this week, and I've created some slides to aid me with this.
>>I have to admit that some examples might not be as bright as I wish, and
>>also there are missing some exercises.
>>I created the slides in english, such that they can be used by a bigger
>>part of the community if need should be.
>>
>>The slides will not cover all that I hope to say in the course, when the
>>slides have finished I will start with a free experimentation phase
>>based on my ants sample implementation
>>http://ruby.brian-schroeder.de/ants/
>>
>>It would be great if some of you could look at the slides and correct
>>the language and if somebody comes up with a great example or exercise I
>>would also be glad for comments.
>>
>>The slides are located at
>>http://ruby.brian-schroeder.de/course/
>
>
> This is great! Can I add your slides to the WhyRuby? repository
> (http://whyruby.rubyforge.org/wiki/wiki.pl?Ruby_Presentations\)?
>
> Curt
>
>

Shure, but the final relase will be on sunday after the course has
finished.
Until then I hope the slides will expand a bit more.

Thanks you. If you could just let me know when you then they are ready, I
will add them to the WhyRuby? repository (they can also be updated at any
time).

Curt

Brian Schröder wrote:

Hello Group,

I need more help.

Gavin Sinclair wrote:

p51. Good exercise. How about another?

Anybody has an idea for an exercise on extending existing classes. So far the only thing I have come up with is:

\exercise{Fibonacci II}{
  Extend \codetype{Integer} with a function fib that calculates the
  corresponding fibonacci number.}

And my creativity is at an all time low.

Hi!

what about
- extending REXML::Element with a method that strips all unnecessary whitespaces and all children
- extending String so you can tell it to remove cpp comments /* remove me */

Of course both tasks could be accomplished without extending those classes. I have no idea in which cases you should write helper methods and when you should extend existing classes... does anybody have some 'heuristics' or best practices?

regards,
Henrik

Hello Group,

I need more help.

Anybody has an idea for an exercise on extending existing classes. So
far the only thing I have come up with is:

\exercise{Fibonacci II}{
   Extend \codetype{Integer} with a function fib that calculates the
   corresponding fibonacci number.}

And my creativity is at an all time low.

      * Sub class (or extend) array to support "card deck" semantics,
        e.g. cut, shuffle, deal, and (*smile*) maybe even stack?

      * Add set-like operations to hash (e.g. &&, ||)

      * Here's one I find this very useful: add aggregate behaviour to
        hashes. For example have { :a=>3, :b=>[0,5,2], :c=>8 } +
        {:b=>[7], :c=>4} return { :a=>3, :b=>[0,5,2,7], :c=>12 }

      * Add some sort of simple substitution cypher to String

> p52. It would be good to teach extending objects, because it's core to
> Ruby, and important when understanding "class methods". But you
> can emphasise that it's advanced material, so students needn't be
> worried if they don't get it straight away. (It's not *that*
> hard to accept, anyway... :slight_smile:
>

Anybody nows of a good example where it is neccessary to extend an
existing object?

As far as I'm concerned, things like:

def Symbol.intern
     self
     end

but I don't think that's quite what your asking.

I have never used this feature and I don't know when to use it in a
sensible way.

     If you're talking about extending individual objects, the only time
I can recall using it extensively was in a little text based adventure
game. It's kind of odd now that I think about it: I love the ability
but I use it very sparingly.

> p55. Missing exercises.

Somebody has an idea for an exercise on using modules (as namespace and
mixin?)

     A linked list or tree package is the semi-standard answer. You can
add it to any class & do "classical" lists & trees. You may want to
note that this isn't very rubyesque thought.
     Maybe a simple version history "memento" setup? Or taint tagging
with more history/details than tainted or not? Or some sort of math
package (& use this to introduce Math)?

     -- Markus

···

On Tue, 2004-10-05 at 10:24, Brian Schröder wrote:

Taken from the Design Patterns book, Decorator pattern:

"Attach additional responsibilities to an object dynamically.
Decorators provide a flexible alternative to subclassing for extending
functionality."

You could extend Integer with a fibonacci method, so that you can
write something like:

puts 0.fibonacci > 0
puts 1.fibonacci > 1
puts 5.fibonacci > 5

My 2 cents.
Ed

···

On Wed, 6 Oct 2004 02:24:12 +0900, Brian Schröder <ruby@brian-schroeder.de> wrote:

Anybody has an idea for an exercise on extending existing classes. So
far the only thing I have come up with is:

--
" Don't relax! It's only your tension that's holding you together."

Brian Schröder wrote:

Hello Group,

I need more help.

Anybody has an idea for an exercise on extending existing classes.

The code below introduce a new string concatenation operator '/' which
concatenates two strings placing '/' beween them. This is useful
when forming path from directory and filename components.

class String
  def /(rhs)
    self.sub(%r{/+$}, '') + '/' + rhs.sub(%r{^/+}, '')
  end
end if

Now you can write the following code:

$dir='/usr/local/bin'
$name='ruby'
$full_path= $dir/$name

Also the '/' operator will make sure that the strings are joined by one and
only one slash. Example:
$dir='/badby/formed/dir///'

$name='///foo'

$dir/$name => '/badby/formed/dir/foo'

Note, that poatterns like '///' were removed.

Hope it helps,
Leo

···

--
[ LEOR _at_ WINLAB _dot_ RUTGERS _dot_ EDU ]