Skip to content

Instantly share code, notes, and snippets.

@joerixaop
Forked from spint/instance_var_caching.rb
Created December 17, 2010 16:53
Show Gist options
  • Save joerixaop/745260 to your computer and use it in GitHub Desktop.
Save joerixaop/745260 to your computer and use it in GitHub Desktop.
# 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