class String # Evaluates a String as a Proc. # # require 'facet/string/to_proc' # # xyp = "|x,y| x + y".to_proc # xyp.class #=> Proc # xyp.call(1,2) #=> 3 # #-- # Note: Sure would be nice if this could # grab the caller's context! #++ def to_proc(context=nil) if context if context.kind_of?(Binding) or context.kind_of?(Proc) Kernel.eval "proc { #{self} }", context else context context.instance_eval "proc { #{self} }" end else Kernel.eval "proc { #{self} }" end end end