All the Perl that's Practical to Extract and Report

Navigation

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Without JavaScript enabled, you might want to
use the classic discussion system instead. If you login, you can remember this preference.

Please Log In to Continue

Speaking as one who has added methods to UNIVERSAL and, on at least one occasion, set @UNIVERSAL::ISA, I'd say there's nothing wrong with monkeying with classes you don't 'own'. What always gave me the heeby jeebies about the way Rails does it is that they chose names that were obvious hostages to fortune.

When I was hacking on Pixie and needed to add methods to UNIVERSAL, everything that went in got a px_ prefix and should probably have had a pixie_ one. (Actually, now I think about it, we used to take advantage of the way you can override Perl's method dispatch by doing $obj->px::pickle, so we could have arranged to use totally opaque names on UNIVERSAL itself:

I just tried writing something similar in Ruby and it can't be done (for values of "can't be done" that involve no more than 10 minutes thought), you're left having to use a hopefully unique prefix for the methods you add.

But you're right; that particular post left me gasping. I particularly liked the "It's the fault of those dashed Japanese people for not understanding that if you change the sub sub version number, you shouldn't go changing the interface of your core classes!" protest. It's not like it hasn't happened with pretty much every sub release of Ruby so far. You'd think he'd be used to it by now. You might, further, think that the maintainers of Rails might have learned by now...

My amusement comes from the idea that Rails could have done the right thing (incidentally avoiding Primitive Obsession [jamesshore.com] as well as monkeysquatting) by using its own String subclass. It's opinionated software. You use its own APIs throughout your system. This is cheap insurance -- and think how easy it would be to fix HTML escaping in one place, for all time.