Class: Regexp

Inherits:
Object show all
Defined in:
lib/capcode/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#arityObject



17
18
19
# File 'lib/capcode/core_ext.rb', line 17

def arity #:nodoc:
  self.source.scan( /(?!\\)[(](?!\?[#=:!>-imx])/ ).length
end

#number_of_capturesObject

:nodoc:



8
9
10
11
12
13
14
# File 'lib/capcode/core_ext.rb', line 8

def number_of_captures #:nodoc:
  c, x = 0, self.source.dup.gsub( /\\\(/, "" ).gsub( /\\\)/, "" )
  while( r = /(\([^\)]*\))/.match( x ) )
    c, x = c+1, r.post_match
  end
  c
end