Skip to content

Instantly share code, notes, and snippets.

@aclarke-iseatz
Forked from anonymous/gist:4331041
Created December 18, 2012 19:23
Show Gist options
  • Save aclarke-iseatz/4331068 to your computer and use it in GitHub Desktop.
Save aclarke-iseatz/4331068 to your computer and use it in GitHub Desktop.
# read contents of file if it exists and hasn't already been read and it exists
@@_file_contents ||= (File.read(file_name).strip if File.exists?(file_name))
-- or --
@@_file_contensts ||= File.exists?(file_name) ? File.read(file_name).strip : nil
@jnwheeler44
Copy link

@@_file_contents ||= if File.exists?(file_name)
                                          File.read(file_name)
                                         end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment