module Sourcerer class SourceCode < String # return the number how often the str is with in the self # by default with \b regex border def frequency(str) begin if str.class == String str= '\b'+str+'\b' end end self.scan(/#{str}/).count end # this is a helper to create source strings from procs def source_formater_for_line_sub trim_comment_out= true if trim_comment_out == true trim_comment= self.match(/^.*#/) unless trim_comment.nil? self.replace trim_comment[0][0..(trim_comment[0].length-2)].concat("\n") end end self.frequency(/{/)+ self.frequency(/def/)- self.frequency(/}/) end def convert_from_proc! self.sub!(/^[\w =]*Proc.new\s*{ */,'Proc.new { ') return self end def convert_from_method! the_params= self.scan(/ *def *[\w\.]*[\( ] *(.*)/)[0][0] self.sub!( self.split("\n")[0], "Proc.new { |#{the_params}|" ) return self end end end