Posts Tagged ‘improvement’
0×18 – More magic symbols
02Mar09
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?
Filed under: Uncategorized | Leave a Comment
Tags: improvement, rails, ruby, symbol