ruby - 'string' to ['s', 'st', 'str', 'stri', 'strin', 'string'] -


what's elegant way of doing

'string' => ['s', 'st', 'str', 'stri', 'strin', 'string'] 

i've been trying think of 1 liner, can't quite there.
solutions welcome, thanks.

you can use abbrev in standard library

require 'abbrev' s = abbrev::abbrev(['string']).keys puts s.inspect 

i must add other way use after requiring abbrev library, .abbrev method added array:

require 'abbrev' s = ['string'].abbrev.keys puts s.inspect 

if order important match return in question, call .sort on keys.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -