Sha256: 52a606acb9a6b4c864e4872a4754528ff99fbf40d3ab21f2d3f6a4c7fb9153c1
Contents?: true
Size: 975 Bytes
Versions: 10
Compression:
Stored size: 975 Bytes
Contents
# TITLE: # Regexp Arity # # DESCRIPTION: # Matchdata methods to produces a hierachical list of a match result. # This also includes Regexp#arity. # # AUTHORS: # - Thomas Sawyer # 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 TestRegexpArity < 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
10 entries across 10 versions & 1 rubygems