lib/wdd-ruby-ext/string.rb in wdd-ruby-ext-0.2.0 vs lib/wdd-ruby-ext/string.rb in wdd-ruby-ext-0.2.1

- old
+ new

@@ -49,22 +49,20 @@ # eg. # # >> "this is that".mgpsub( [ [/(that)/, 'really $1!'], [/this/, 'that'] ] ) # => that is really that!" # - def mgpsub(key_value_pairs=[].freeze) - def mgpsub(string, key_value_pairs=[].freeze) - regexp_fragments = key_value_pairs.collect { |k,v| k } - string.gsub(Regexp.union(*regexp_fragments)) do |match| - replacement_term = key_value_pairs.detect{|k,v| k=~match}[1] - vars = %w{$1 $2 $3 $4 $5 $6 $7 $8 $9 $` $& $’} - vars.each do |var| - tm_safe_log var - tm_safe_log eval(var)||'' - replacement_term.gsub!( Regexp.compile("\\"+var), eval(var)||'' ) - end - replacement_term + def mgpsub(string, key_value_pairs=[].freeze) + regexp_fragments = key_value_pairs.collect { |k,v| k } + string.gsub(Regexp.union(*regexp_fragments)) do |match| + replacement_term = key_value_pairs.detect{|k,v| k=~match}[1] + vars = %w{$1 $2 $3 $4 $5 $6 $7 $8 $9 $` $& $’} + vars.each do |var| + tm_safe_log var + tm_safe_log eval(var)||'' + replacement_term.gsub!( Regexp.compile("\\"+var), eval(var)||'' ) end + replacement_term end end # trims the string to the nearest word boundary ensuring that the resulting length is less than max_length def trim_to_word( max_length )