2007/11/28

String#to_proc

Raganwald is one of my favorite bloggers. Every entry he writes inspires me and makes me think. A while ago he ported String#to_proc from Oliver Steele's functional javascript library to ruby. You have to read his entry for yourself but one thing that caught my eye was his definition of the factorial function using String#to_proc:


factorial = "(1.._).inject &'*'".to_proc
factorial[5] # -> 120


I don't know about you, but I think implementations like this are showing us whats possible in this language.

Never stop writing raganwald! Thanks.