Skip to content

Instantly share code, notes, and snippets.

@spint
Created December 17, 2010 09:42
Show Gist options
  • Save spint/744714 to your computer and use it in GitHub Desktop.
Save spint/744714 to your computer and use it in GitHub Desktop.
Caching 'false' in an instance variable in ruby (rails)
# this only gets cached in @admin if true
# how to cache this also in case of false?
def admin?
@admin ||= has_role? 'admin'
end
#is the following ok?
def admin?
return @admin if defined? @admin
@admin ||= has_role? 'admin'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment