Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

ObjectSpace#dump

(untyped obj, ?output: ::Symbol) -> (::String | ::File | nil)
dump(obj, output: :string)

Dump the contents of a ruby object as JSON.

output can be one of: :stdout, :file, :string, or IO object.

  • :file means dumping to a tempfile and returning corresponding File object;

  • :stdout means printing the dump and returning nil;

  • :string means returning a string with the dump;

  • if an instance of IO object is provided, the output goes there, and the object is returned.

This method is only expected to work with C Ruby. This is an experimental method and is subject to change. In particular, the function signature and output format are not guaranteed to be compatible in future versions of ruby.