« Followup on the EMail Experiment | Main

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)`

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