Class: Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/case_check/core-ext.rb

Instance Method Summary collapse

Instance Method Details

#scan(s) ⇒ Object

Like String#scan, except that it returns an array of MatchData instead of strings Works incrementally (returning nil) if given a block



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/case_check/core-ext.rb', line 38

def scan(s)
  data = []
  remaining = s
  while md = self.match(remaining)
    if block_given?
      yield md
    else
      data << md
    end
    remaining = md.post_match
  end
  block_given? ? nil : data
end