« Followup on the EMail Experiment | Main | A subtle potential bug in most Rails applications »

February 02, 2012

TrackBack

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

Listed below are links to weblogs that reference Smart constants:

Comments

Robert Starsi

good tip. Coming from PHP I am only slowly getting used to the idea that I can just open up almost anything in Ruby and attach my own methods. The result is indeed a conscious code.

Austinthecoder

Interesting idea, but I'm not a fan. You're just aliasing `==` as `in?` for these two String objects. I'd prefer `==` as it's immediately obvious what the check is. I think the cells should be an object called Cell instead of a string. Then you could add this method:

```
def contains?(element)
# return true if it contains this element (water, air, etc)
end
```

Then in your case statement: `cave.cell_below.contains?(AIR)`

The comments to this entry are closed.

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.