Sha256: c49cd462c7d98831445dc74f8fd38ef788a882c0255f39b867f89e276d2adbee
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 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! the_params= self.scan(/ *def *[\w\.]*[\( ] *(.*)/)[0][0] 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.2 | lib/sourcerer/source_code.rb |