class method
Prism.dump_options
dump_options(options)
lib/prism/ffi.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/ffi.rb, line 449
def dump_options(options)
template = +""
values = []
template << "L"
if (filepath = options[:filepath])
values.push(filepath.bytesize, filepath.b)
template << "A*"
else
values << 0
end
template << "l"
values << options.fetch(:line, 1)
template << "L"
if (encoding = options[:encoding])
name = encoding.is_a?(Encoding) ? encoding.name : encoding
values.push(name.bytesize, name.b)
template << "A*"
else
values << 0
end
template << "C"
values << (options.fetch(:frozen_string_literal, false) ? 1 : 0)
template << "C"
values << dump_options_command_line(options)
template << "C"
values << dump_options_version(options[:version])
template << "C"
values << (options[:encoding] == false ? 1 : 0)
template << "C"
values << (options.fetch(:main_script, false) ? 1 : 0)
template << "C"
values << (options.fetch(:partial_script, false) ? 1 : 0)
template << "C"
values << (options.fetch(:freeze, false) ? 1 : 0)
template << "L"
if (scopes = options[:scopes])
values << scopes.length
scopes.each do |scope|
locals = nil
forwarding = 0
case scope
when Array
locals = scope
when Scope
locals = scope.locals
scope.forwarding.each do |forward|
case forward
when :* then forwarding |= 0x1
when :** then forwarding |= 0x2
when :& then forwarding |= 0x4
when :"..." then forwarding |= 0x8
else raise ArgumentError, "invalid forwarding value: #{forward}"
end
end
else
raise TypeError, "wrong argument type #{scope.class.inspect} (expected Array or Prism::Scope)"
end
template << "L"
values << locals.length
template << "C"
values << forwarding
locals.each do |local|
name = local.name
template << "L"
values << name.bytesize
template << "A*"
values << name.b
end
end
else
values << 0
end
values.pack(template)
end
Convert the given options into a serialized options string.