End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
ObjectSpace#dump
ObjectSpace.dump(obj[, output: :string]) # => "{ ... }"
ObjectSpace.dump(obj, output: :file) # => #<File:/tmp/rubyobj20131125-88733-1xkfmpv.json>
ObjectSpace.dump(obj, output: :stdout) # => nil
ext/objspace/lib/objspace.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/ext/objspace/lib/objspace.rb, line 24
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.
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
#garbage_collect
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1