Module: Gemmy::Patches::StringPatch::InstanceMethods::Range

Defined in:
lib/gemmy/patches/string_patch.rb

Instance Method Summary collapse

Instance Method Details

#range(pattern, offset = 0) ⇒ Object

facets Gets the start/end indexes of a match to <pattern> only considers first match



103
104
105
106
107
108
109
110
111
112
# File 'lib/gemmy/patches/string_patch.rb', line 103

def range(pattern, offset=0)
  unless Regexp === pattern
    pattern = Regexp.new(Regexp.escape(pattern.to_s))
  end
  string = self[offset..-1]
  if md = pattern.match(string)
    return (md.begin(0)+offset)..(md.end(0)+offset-1)
  end
  nil
end