Hi --

On Wed, 7 May 2008, Phillip Gawlowski wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> A: It makes it difficult to follow the conversation
> !: Why is top posting bad?
>
> Zoop Zoop wrote:
> | Robert, could you explain a bit more what you mean?
>
> He means that you can crack open Ruby's classes when ever you want.
>
> Adding a 'class String;end' definition anywhere in your code opens up
> String, and adds your method. This is called Monkeypatching, and you'll

Not by everyone :-) I know I'm in the minority, but I'll put in a word
for those of us who dislike and, at least in my case, do not (and
never will) use the term "monkeypatching". It seems to me to do a very
bad job of conveying what's actually happening, which is neither
patching, in any sense that I've ever heard the term used, nor
"monkeying" (i.e., monkeying with the code, or monkeying around). All
"monkey" connotations are negative, and the issue of whether or not
its a good idea to modify existing classes in any given case is a lot
more complicated.

> get fun results if several people get the same idea, and all of them
> monkeypatch String.
>
> | Do you mean adding the code directly to the original string.rb file?
>
> No. Any source file in your application / directory structure. as long
> as require can find it, you can use it.
>
> | Are there other solutions?
>
> Extend String with your method.

Do you mean extending an individual string? That's probably my
favorite way of adding functionality to core-class objects.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
   INTRO TO RAILS         June 24-27           London (Skills Matter)
See http://www.rubypal.com for details and updates!