Class: Console::Format::Safe
- Inherits:
-
Object
- Object
- Console::Format::Safe
- Defined in:
- lib/console/format/safe.rb
Overview
A safe format for converting objects to strings.
Handles issues like circular references and encoding errors.
Instance Method Summary collapse
-
#dump(object) ⇒ Object
Dump the given object to a string.
-
#initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8) ⇒ Safe
constructor
Create a new safe format.
Constructor Details
#initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8) ⇒ Safe
Create a new safe format.
20 21 22 23 24 |
# File 'lib/console/format/safe.rb', line 20 def initialize(format: ::JSON, limit: 8, encoding: ::Encoding::UTF_8) @format = format @limit = limit @encoding = encoding end |
Instance Method Details
#dump(object) ⇒ Object
Dump the given object to a string.
30 31 32 33 34 |
# File 'lib/console/format/safe.rb', line 30 def dump(object) @format.dump(object, @limit) rescue SystemStackError, StandardError => error @format.dump(safe_dump(object, error)) end |