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