Sha256: 0517ce11902b205a27d8accdc0ebb676373ae73490671da44fda18ff86a02a54
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
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! #self.sub! the_params= self.scan(/ *def *[\w]*[\( ] *(.*)/)[0][0] puts the_params.inspect self.sub!( self.split("\n")[0], "Proc.new { |#{the_params}|" ) return self end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sourcerer-0.5.1 | lib/sourcerer/source_code.rb |