md5 = Digest::MD5.file('path_to_file').hexdigest

this would read file in blocks and avoid reading the whole file in RAM which is done in File.read()