Posts Tagged ‘improvement’

With just that small addition:

class Symbol
alias_method :old_eeq, :”===”

def ===(obj)
(obj.respond_to?(self) && obj.send(self)) ||
old_eeq(obj)
end
end

you can do things like

case current_user
when :admin? then “admin”
when :regular? then “something_for_regulars”
when :guest? then “do_guest_stuuff”
else “huh”
end

Isn’t that cool much more readable?