class Benchmark::Memory::HeldResults::Serializer
Serialize objects for holding between runs.
Attributes
object[R]
@return [Object] The object to serialize.
Public Class Methods
load(json)
click to toggle source
Load an object from a JSON document.
@param json [String] A JSON document as a string.
@return [Object] The object converted from the JSON document.
# File lib/benchmark/memory/held_results/serializer.rb, line 13 def self.load(json) json = JSON.parse(json) if json.is_a?(String) new.load(json).object end
new(object = nil)
click to toggle source
Instantiate a new serializer.
@param object [Object] The object to serialize.
# File lib/benchmark/memory/held_results/serializer.rb, line 21 def initialize(object = nil) @object = object end
Public Instance Methods
load(_hash)
click to toggle source
Convert a JSON document into an object.
@param _hash [Hash] A JSON document hash.
@return [Object] @raise [NotImplementedError]
If the inheriting subclass didn't implement.
# File lib/benchmark/memory/held_results/serializer.rb, line 35 def load(_hash) fail( NotImplementedError, "You must implement a concrete version in a subclass" ) end
to_h()
click to toggle source
Convert the object to a Hash.
@return [Hash] The object as a Hash. @raise [NotImplementedError]
If the inheriting subclass didn't implement.
# File lib/benchmark/memory/held_results/serializer.rb, line 47 def to_h fail( NotImplementedError, "You must implement a concrete version in a subclass" ) end
to_json()
click to toggle source
Convert the object to a JSON document.
@return [String] The object as a JSON document.
# File lib/benchmark/memory/held_results/serializer.rb, line 57 def to_json JSON.generate(to_h) end
Also aliased as: to_s