Permalink
Browse files

cache procs

  • Loading branch information...
1 parent 24cfb12 commit 4fa480c45ff43540fe411831b650fe35ba1ba7cf @defunkt committed Feb 16, 2008
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/ambition/sexp_translator.rb
@@ -2,10 +2,14 @@
module Ambition
class SexpTranslator
+ @@block_cache = {}
+
def self.translate(block)
- klass = Class.new { define_method(:proc_to_method, block) }
- body = ParseTree.translate(klass, :proc_to_method)[2][1..-1]
- [:proc, *body]
+ @@block_cache[block.to_s] ||= begin
+ klass = Class.new { define_method(:proc_to_method, block) }
+ body = ParseTree.translate(klass, :proc_to_method)[2][1..-1]
+ [:proc, *body]
+ end
end
end
end

0 comments on commit 4fa480c

Please sign in to comment.