Must people love a new feature in Ruby called Symbol#to_proc, but there are not many good explanations of it. The concept is actually fairly straightforward, but the Ruby implementation is fairly complex. The following is an explanation that assumes no knowledge of Ruby.
In the book Beautiful Code some code is more beautiful than other code. But there is little doubt that the opening chapter presents a regular expression matcher in a beautifully succinct fashion. As the author Brian Kernighan states:
“I don’t know of another piece of code that does so much in so few lines while providing such a rich source of insight and further ideas.”
The example is written in C. I wondered if a more beautiful version could be created using a newer programming language. But we can maintatin the advantages of C and work at a slightly higher level by using lists. Since this code also uses recursion and pattern matching, Haskell is a very natural replacement.
The script I use most frequently is a script for extracting files. If you work from the linux command line, it is impossible to remember which program with which flags should be used to extract a file. This is something the computer should do for you! This extraction script solves the problem, and you can configure the first lines of the script to match any filetype. I use it so often that I have it aliased to ‘e’