Hi --

On Fri, 22 Aug 2003, Ben Giddings wrote:

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

Definitely -- but don't forget, just to give full credit, the Pickaxe
itself leads the way here, by taking some of its examples from the
standard distribution.

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

Actually one thing I find myself doing sometimes is grepping the
library when I'm curious about how common a given idiom is (or isn't).
Obviously there's a lot of other Ruby code in the world, but I'm
always curious to see what's being done in the distribution.

For example:

# How common is each_with_index?
  $ grep 'each_with_index' `find . -name "*.rb"` | wc -l
        10

# rough stats on camelCase method names
  $ grep 'def [a-z]\+' `find . -name "*.rb"` |
      wc -l
      4630
  $ grep 'def [a-z]\+[A-Z]\+' `find . -name "*.rb"` | wc -l
      44

and so on.  It can actually be quite informative and interesting.


David

-- 
David Alan Black
home: dblack / superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav