Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2011 11:22
Show Gist options
  • Save anonymous/796581 to your computer and use it in GitHub Desktop.
Save anonymous/796581 to your computer and use it in GitHub Desktop.
def image? #better because file_type only called once and result stored instead of recalculated?
if ft = file_type
['.jpg','.jpeg'].include?(ft.downcase)
else
return false
end
end
def image_alternative? #worse because needs to call file_type twice?
file_type.nil? ? ['.jpg','.jpeg'].include?(file_type.downcase) : false
end
def file_type
@filetype ||= self.scan(/(\.\w+?)\z/).flatten[0]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment