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
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