« Deploying Rails Applications | Main | Art in Programming »

August 30, 2007

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c41c69e200e54ed4ee698833

Listed below are links to weblogs that reference Superators: neat Ruby hack:

Comments

David Precious

To me, that sounds like a way to reduce the readability of your code... anyone viewing that bit of code is going to think "WTF does that do?" and have to go look up the "superator" definition to find out.

Sure, it's an neat trick, but not something I'd imagine being useful in quality code.

Ian Bicking

Where this gets weird is that it's not just the type of object you are adding that gets extended; every object is extended in weird ways because of the unary operators that are being overloaded. That is, something like <=- involves not just overriding <= in String (fine enough) but also "-" in everything else, because you have to keep track of *anything* in the system that has been minused in case it gets less-than-or-equaled-to later.

A less intrusive trick in Python that would work in Ruby is |operator|, where "operator" is an object that just implements "|" appropriately: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122

andy

Clever, but I also prefer

'Clarity Over Cleverness'.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now available
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.

Site Search

  • Google Search

    The web
    PragDave