Efficient way to sort an array of numbers and string in ruby?

One way is to partition your array by those elements being Integer, to make sure they remain first and then sort the elements of each array:

[4,2,'b',5,'c','a',7].partition { |e| e.is_a?(Integer) }.flat_map(&:sort)
# [2, 4, 5, 7, "a", "b", "c"]

arr.sort_by { |e| [e.is_a?(Integer) ? 0 : 1, e] }
  #=> [2, 4, 5, 7, "a", "b", "c"] 

[22, 'efg', 0, 'abc', -4].sort_by { |e| [e.is_a?(Integer) ? 0 : 1, e] }
  #=> [-4, 0, 22, "abc", "efg"] 

See Enumerable#sort_by. sort_by performs pair-wise comparisons of 2-element arrays using the method Array#<=>. See especially the third paragraph of that doc.

The following could be used if, as in the example, the integers are single digits and the strings are single characters.

arr.sort_by(&:ord)
  #=> [2, 4, 5, 7, "a", "b", "c"] 

See Integer#ord and String#ord.