June 2007
Intermediate to advanced
294 pages
8h 6m
English
I’ll close this chapter with a tiny script that I didn’t even write. I certainly wish I had, because it’s remarkably useful, especially for making your use of map, inject, and similar methods much more elegant. It’s an example of the best kind of syntactic sugar, and it comes directly from the Ruby Extensions Project at http://extensions.rubyforge.org. This script and all other scripts at that site are licensed under the same terms as Ruby itself, which is what allows me to use it in this chapter.[31] The code is extremely simple.
#!/usr/bin/env ruby Symbol.to_proc
class Symbol
def to_proc()
Proc.new { |obj, *args| obj.send(self, *args) }
end
endWhat’s the point of this? It lets you use uc_words ...
Read now
Unlock full access