Slide 53
Slide 53 text
def extract_rest_parameters(*args, **options, &block)
{ :* => args,
:** => options,
:"..." => [args, options, block],
:& => block }
end
trace_point = TracePoint.new(:call) do |tp|
rest_names = tp.parameters.filter_map { _2 if [:*, :**, :&].include?(_2) }
rest_variables = begin
tp.binding.eval("extract_rest_parameters(#{rest_names.join(',
')})").slice(*rest_names)
rescue SyntaxError
tp.binding.eval("extract_rest_parameters(...)").slice(:"...")
end
pp rest_variables
end
trace_point.enable