Learning from the standard library

B

Ben Giddings

There are a lot of good ways to learn how to do things in Ruby. I
happen to think the Pickaxe (http://www.pragmaticprogrammer.com/ruby/)
is a great place to start. But at a certain point, it isn't enough.
For me, when it comes to open-source languages, the next step is often
looking at examples, in particular, the standard library.

When I first started doing this with Ruby, one thing hit me right away.
Most of the standard library files use the shortcut:

class << self
...
end

This is one of the many ways of defining class methods in Ruby, but
while it is extremely common in the standard library, it's one that I
don't believe is mentioned in the Pickaxe. In addition to this, there
were all kinds of other interesting, but odd things lurking in the
standard library, like instance_eval.

So, what I'm wondering is this. Do other people use the standard
library as a place to learn how to do things? If not, why not? If so,
which files do you find most useful, most confusing, most well written, etc?

What I've noticed:

singleton.rb: I am amazed by how small it is, but the magic is deep and
complex. Using an instance eval, but using the %{} syntax is really
tricky. There are no comments to help a newcomer learn, or a maintainer
maintain, but once you get it, it is pretty obvious what's happening.

date.rb: At first glance, it appears pretty simple, but then there's the
"once" method. It is a triky one too. Once again, no comments to speak of.

profiler.rb: Ouch. Scary. I wouldn't expect a profiler to be easy to
understand, but this one is really opaque.

net/http.rb: Really well documented. Has some great examples of using
classes well, and shows a lot of the language flexibility, but the
comments are somewhat sparse.

Btw, I'm basing this off Ruby 1.6.8. I haven't gotten around to
installing 1.8 on this machine yet because I haven't found RedHat 9 RPMs.

Ben
 
S

Sascha Dördelmann

Ben Giddings said:
There are a lot of good ways to learn how to do things in Ruby. I
happen to think the Pickaxe (http://www.pragmaticprogrammer.com/ruby/)
is a great place to start. But at a certain point, it isn't enough.
For me, when it comes to open-source languages, the next step is often
looking at examples, in particular, the standard library.

I'd agree that this is a standard learning curve: You start with a
tutorial or with a book. You practice. You want to dig into details
and get an idea about what's common practice.

Ruby could learn from Smalltalk in this place. The library is always
present because of the browser's view of the complete class
repository. Any pattern which can't be found in the library is said to
be without example.

Cheers
Sascha
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top