You can use Abbrev in the standard library
require 'abbrev' s = Abbrev::abbrev(['string']).keys puts s.inspect
I have to add another way to use this by requiring the Abbrev library, with the .abbrev method added to Array:
require 'abbrev' s = ['string'].abbrev.keys puts s.inspect
If ordering is important to match your return in question, just call .sort on keys .
vgoff source share