Smoke Signals

Wednesday, April 20, 2005

Ruby Ruby Ruby, where art thou syntax?

Jeez, just when I think I am getting the hang of it I see this: if layout ||= active_layout and action_has_layout? WTF? Thanks to the help of some friendly fellas on the Rails list who pointed me to the Ruby Idioms Page and using irb to test it I was able to figure it out. Let me break it down for you: "if layout ||=" means if layout is nil assign the next variable to layout, what about the and... "||= active_layout and action_has_layout?" that means assign the active_layout variable to layout if layout is empty AND action_has_layout? is true. Whew!

One of the things I have realized about Ruby is, you write less code but it is harder to read if you are a Ruby Nuby. It lends itself to some good refactoring though. I am constantly refactoring code after finding tidbits like this.

1 Comments:

Post a Comment

<< Home