Sha256: 9db2c738f632bffc30fe1dcf3a24f01d054a8da63ec2ba86b7e7a9d57424b686
Contents?: true
Size: 703 Bytes
Versions: 2
Compression:
Stored size: 703 Bytes
Contents
class String # based on https://www.ruby-forum.com/topic/193809#844629 def to_r if self.strip.match(/\A\/(.*)\/(.*)\Z/mx) regexp, flags = $1, $2 fail "Not a valid regular expression. Valid flags in (/regexp/flags) are x, i and m" \ if !regexp || flags =~ /[^xim]/m x = /x/.match(flags) && Regexp::EXTENDED i = /i/.match(flags) && Regexp::IGNORECASE m = /m/.match(flags) && Regexp::MULTILINE rxp = Regexp.new regexp , [x,i,m].inject(0){|a,f| f ? a+f : a } def rxp.from_string?; false end rxp else # build regexp from regular string rxp = Regexp.new( self ) def rxp.from_string?; true end rxp end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
log2mail-0.0.1.pre3 | lib/ext/string.rb |
log2mail-0.0.1.pre2 | lib/ext/string.rb |