Sha256: 8674c1865f2a6e58acab3d48d2274c778b1b8993744c257bd485fa89e993563f

Contents?: true

Size: 780 Bytes

Versions: 26

Compression:

Stored size: 780 Bytes

Contents

class Regexp
  # Returns the number of backreferencing subexpressions.
  #
  #   /(a)(b)(c)/.arity  #=> 3
  #   /(a(b(c)))/.arity  #=> 3
  #
  # Note: This is not perfect, especially with regards to \x
  # and embedded comments.
  def arity
    self.source.scan( /(?!\\)[(](?!\?[#=:!>-imx])/ ).length
  end
end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCRegexp < Test::Unit::TestCase

    def test_arity
      r = /(1)(2)(3)/
      assert_equal( 3, r.arity )
      r = /(1)(2)(3)(4)/
      assert_equal( 4, r.arity )
      r = /(1)(2)((a)3)/
      assert_equal( 4, r.arity )
      r = /(?#nothing)(1)(2)(3)(?=3)/
      assert_equal( 3, r.arity )
    end

  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/regexp/arity.rb
facets-1.0.0 lib/facet/regexp/arity.rb
facets-1.0.3 packages/core/lib/facet/regexp/arity.rb
facets-1.2.1 lib/facets/core/regexp/arity.rb
facets-1.2.0 lib/facets/core/regexp/arity.rb
facets-1.1.0 lib/facet/regexp/arity.rb
facets-1.3.0 lib/facets/core/regexp/arity.rb
facets-1.3.2 lib/facets/core/regexp/arity.rb
facets-1.3.1 lib/facets/core/regexp/arity.rb
facets-1.3.3 lib/facets/core/regexp/arity.rb
facets-1.4.2 lib/facets/core/regexp/arity.rb
facets-1.4.0 lib/facets/core/regexp/arity.rb
facets-1.4.1 lib/facets/core/regexp/arity.rb
facets-1.4.3 lib/facets/core/regexp/arity.rb
facets-1.4.4 lib/facets/core/regexp/arity.rb
facets-1.4.5 lib/facets/core/regexp/arity.rb
facets-1.7.38 lib/facets/core/regexp/arity.rb
facets-1.7.0 lib/facets/core/regexp/arity.rb
facets-1.7.30 lib/facets/core/regexp/arity.rb
facets-1.7.46 lib/facets/core/regexp/arity.rb