On Sep 28, 2005, at 1:46 PM, Elf M. Sternberg wrote:

> I'm afraid that I'm coming from Python, a B&D language where I'm  
> used to
> everything be spelled out cleanly, and although I programmed in  
> Perl for
> many years that was also many years ago.  Ruby is baffling the heck  
> out
> of me.

Welcome to Ruby.  Hopefully it will stop baffling you very soon now.  ;)

> I've been looking at two examples, and I was wondering if someone  
> could
> explain to me what the Hell is going on.

I'll sure try.

> The first is from
> http://redhanded.hobix.com/bits/hyperextended.html, and my question is
> about the 'extend' keyword there.  Where does that came from?  In what
> object is it defined?

It is defined in Object.

It adds the instance methods from the module parameter to the object  
it is called on.  In your example it was called with an implicit self  
as the target object and self was Mix.  Thus the methods get added to  
the  class itself (becoming class methods).

For what it's worth, I don't like that example very much.  ;)

> In the same
> breath, what does the 'super' keyword do in the append_features()
> method,

super calls the overridden version of the current method.  In this  
case, append_features() in Module itself.

> and why does it need a 'self' in front of it?

That's how we define class method.  The following are equivalent:

module Mix
     def Mix.append_features() end
     def self.append_features() end
end

> Second, I've seen the following constructions:
>
> validates :url :with => %r{^http:.+\.(gif|jpg|png)$}i

You're missing a comma after :url, but I get the idea.

>         and
>
> check_associations %w(friends downloads links)
>
> I'm guessing that the "%r" and "%w" are the ruby equivalents of perl's
> qr{} and qw{} constructs

Bingo.

> (does this mean there's a %qq() and %qx() as
> well?),

Sure:

%w{...}            Array from whitespace split, spaces can be escaped  
to ignore
%W{...}            as above, but with double quoted String subs like # 
{...}
%q{...}            single quoted String
%Q{...} or %{...}  double quoted String
%x{...}            shell command


> but I can't find documentation to that effect inside the
> references available on-line.  (And before someone says "Buy the
> Pickaxe!" I'll just say that I spent my book budget this month on the
> Rails book and any other purchases will have to wait until my next
> paycheck.)

<laughs>  Well, the Pickaxe is a great book, but we try to be helpful.

James Edward Gray II