Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::SafeMarshal::Visitors::ToRuby#visit_Gem_SafeMarshal_Elements_WithIvars
visit_Gem_SafeMarshal_Elements_WithIvars(e)
lib/rubygems/safe_marshal/visitors/to_ruby.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/safe_marshal/visitors/to_ruby.rb, line 79
def visit_Gem_SafeMarshal_Elements_WithIvars(e)
object_offset = @objects.size
push_stack "object"
object = visit(e.object)
ivars = map_ivars(object.class, e.ivars)
case e.object
when Elements::UserDefined
if object.class == ::Time
internal = []
ivars.reject! do |k, v|
case k
when :offset, :zone, :nano_num, :nano_den, :submicro
internal << [k, v]
true
else
false
end
end
s = e.object.binary_string
# 122 is the largest integer that can be represented in marshal in a single byte
raise TimeTooLargeError.new("binary string too large", stack: formatted_stack) if s.bytesize > 122
marshal_string = "\x04\bIu:\tTime".b
marshal_string.concat(s.bytesize + 5)
marshal_string << s
# internal is limited to 5, so no overflow is possible
marshal_string.concat(internal.size + 5)
internal.each do |k, v|
k = k.name
# ivar name can't be too large because only known ivars are in the internal ivars list
marshal_string.concat(":")
marshal_string.concat(k.bytesize + 5)
marshal_string.concat(k)
dumped = Marshal.dump(v)
dumped[0, 2] = ""
marshal_string.concat(dumped)
end
object = @objects[object_offset] = Marshal.load(marshal_string)
end
when Elements::String
enc = nil
ivars.reject! do |k, v|
case k
when :E
case v
when TrueClass
enc = "UTF-8"
when FalseClass
enc = "US-ASCII"
else
raise FormatError, "Unexpected value for String :E #{v.inspect}"
end
when :encoding
enc = v
else
next false
end
true
end
object.force_encoding(enc) if enc
end
ivars.each do |k, v|
object.instance_variable_set k, v
end
object
end
No documentation available