rewrite the variables swap code in the ruby-way