If section may be a different line, rather than "pages" , you should use something like mguymon . But if it can only be nil , false or "pages" , this code is more concise:
%li{ class:section && 'current' } %a{ :href => "#pages" } Pages
This uses the principle that HAML skips the nil or false attributes, and each object in Ruby evaluates to true , with the exception of: false and nil .
So, if section is different from nil or false , then section && 'current' displays 'current' otherwise, it returns false , omitting the class attribute.
source share