1

Is there a tmpfs kind of solution where I can write into Ruby's memory which only persists until that ruby instance is complete.

File.write('/ruby_tmpfs/path/to/file', 'Some glorious content')

It get consumed in same script like this:

read_file_function_i_cannot_change_which_expects_file_path('/ruby_tmpfs/path/to/file')
Jean
  • 21,665
  • 24
  • 69
  • 119

1 Answers1

0

Is there a tmpfs kind of solution where I can write into Ruby's memory which only persists until that ruby instance is complete.

tmpfs is a temporary file storage paradigm implemented in many Unix-like operating systems. It is intended to appear as a mounted file system, but data is stored in volatile memory instead of a persistent storage device. https://en.wikipedia.org/wiki/Tmpfs

I've never heard of such a feature in Ruby or its stdlib.

Searching for "ruby in-memory file" revealed memfs, which I have never heard of before today, but sounds relevant.

MemFs is an in-memory filesystem .. intended for tests but you can use it for any other scenario needing in memory file system.

Using only the stdlib, mktmpdir is probably the best alternative. It will use non-volatile storage, but the OS will eventually delete it.

Jared Beck
  • 16,796
  • 9
  • 72
  • 97