Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities.rb

Overview

This just helps in a couple places, and I’m putting it here.

Instance Method Summary collapse

Instance Method Details

#to_reObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/utilities.rb', line 3

def to_re
  source, options = ( /^\/(.*)\/([^\/]*)$/.match(self) )? [$1, $2] : [self,nil]
  
  mods = 0
  
  options.each_char do |c| 
    mods |= case c
      when 'i' then Regexp::IGNORECASE
      when 'x' then Regexp::EXTENDED
      when 'm' then Regexp::MULTILINE
    end
  end unless options.nil? or options.empty?
      
  Regexp.new source, mods
end