Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
ObjectSpace#dump
dump(obj, output: :string)
ext/objspace/lib/objspace.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/objspace/lib/objspace.rb, line 28
def dump(obj, output: :string)
out = case output
when :file, nil
require 'tempfile'
Tempfile.create(%w(rubyobj .json))
when :stdout
STDOUT
when :string
+''
when IO
output
else
raise ArgumentError, "wrong output option: #{output.inspect}"
end
ret = _dump(obj, out)
return nil if output == :stdout
ret
end
Dump the contents of a ruby object as JSON.
output can be one of: :stdout, :file, :string, or IO object.
-
:filemeans dumping to a tempfile and returning correspondingFileobject; -
:stdoutmeans printing the dump and returningnil; -
:stringmeans returning a string with the dump; -
if an instance of
IOobject 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.
See also
.undefine_finalizer
#dump_all
.trace_object_allocations_stop
#dump_shapes
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0