Abbrev from ruby standard lib

Did you know about Ruby’s standard lib Abbrev? No? Well then let’s take a look!

What Abbrev does

For each string in an array Abbrev gives you all possible uniq abbreviations:

require 'abbrev'

['table', 'wall'].abbrev
=> {"table"=>"table", "tabl"=>"table", "tab"=>"table", "ta"=>"table", "t"=>"table", "wall"=>"wall", "wal"=>"wall", "wa"=>"wall", "w"=>"wall"}

The Implementation is really simple and gives you 2 possibilities how to get your abbreviations. Either by Abbrev::abbrev(words, pattern = nil) or by calling #abbrev directly on any Array.

What’s it good for?

I think CLI’s could use it. For example with Git’s cli you can just call shortest possible abbreviation instead of original full command. And it saves a lot of keystrokes.

I can’t find any other valid case yet. But for some reason i really like the library. So i was just playing a bit for now and created this gem AbbreviatedMethods. With it you can call all your’s objects methods by their’s shortest possible abbreviations:

I don’t think it’s really useful in production but definitelly interesting thing to play with. Have fun!

P.S.: If you find any use-case please let me know

About me

Hi, i'm Přemysl Donát and this is my place.

This is my picture:

Premysl Donat at Balaton lake

I'm a web developer. I like Ruby the most but i'm fine with other technology also. After all, it's just technology.

I work at I also have my own tiny company Imagine Anything.

One of my side projects is It's a web app which helps you to easily connect your business with accounting(czech market only right now). Check it out: logo

Have a good one, Přemek

Follow @Masa331