Depending on your circumstances, and if the instance variables do not already have an existing value that you want to keep, if the value is objequal nil, then it may not be a problem to just set them to nil.
, :
def set_instance_variables_for_non_nil_values(h, *keys)
keys.each do |key|
instance_variable_set "@#{key}", h[key] unless h[key].nil?
end
end
:
set_instance_variables_for_non_nil_values obj, 'num_x', 'num_y',
'num_iterations', 'pe'