Read files in Ruby

Tagged with Ruby

Language: Ruby

View as text

# load a file into a string
def get_file_as_string(filename)
  data = ''

  File.open(filename, "r") { |f|
      data = f.read
  }
  
  return data
end
Last updated at 06:36 AM on Aug 08, 2008 by Brian Hogan

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.