title: Sort Integer Array Ruby
body: <blockquote>
    <p>Have the function PermutationStep (num) take the num parameter being passed and return the next number greater than num using the same digits. For example: if num is 123 return 132, if it's 12453 return 12534. If a number has no greater permutations, return -1 (ie. 999) </p>
  </blockquote>
  
  <p>Here's my code. I'd like to sort an array of large integers in numerical order. Using the regular sort method doesn't give the right order for some numbers. Is there a <code>sort_by</code> structure that I can replace 'sort' with in my code below? </p>
  
  <pre><code>def PermutationStep(num)
      num = num.to_s.split('').map {|i| i.to_i}
      permutations = num.permutation.to_a.sort #&lt;= I want to sort by numerical value here
      permutations.each_with_index do |n, idx|
          if n == num
              if n == permutations[-1]
                  return -1
              else
                  return permutations[idx+1].join.to_i
              end
          end
      end
  end
  </code></pre>
  
  <p>For example, 11121. When I run the code it gives me 11121.I want the next highest permutation, which should be 12111.</p>
  
  <p>Also, when I try <code>{ |a,b| b &lt;=&gt; a }</code>, I also get errors. </p>