Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cache procs

  • Loading branch information...
commit 4fa480c45ff43540fe411831b650fe35ba1ba7cf 1 parent 24cfb12
@defunkt authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/ambition/sexp_translator.rb
View
10 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
Please sign in to comment.
Something went wrong with that request. Please try again.