h = {1 => 'st', 2 => 'nd', 3 => 'rd'}.tap {|h| h.default = 'th'}
f = -> n {(11..13).include?(n % 100) ? h.default : h[n % 10]}
p [1, 23, 12].map {|n| [n, n.to_s + f.(n)]}
aCA9IHsxID0+ICdzdCcsIDIgPT4gJ25kJywgMyA9PiAncmQnfS50YXAge3xofCBoLmRlZmF1bHQgPSAndGgnfQpmID0gLT4gbiB7KDExLi4xMykuaW5jbHVkZT8obiAlIDEwMCkgPyBoLmRlZmF1bHQgOiBoW24gJSAxMF19CnAgWzEsIDIzLCAxMl0ubWFwIHt8bnwgW24sIG4udG9fcyArIGYuKG4pXX0K