diff options
author | Jeremy Evans <[email protected]> | 2020-03-06 13:03:58 -0800 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2020-03-06 13:06:49 -0800 |
commit | f991340e07e76038b044d73ef41bd0cdeb68cf62 (patch) | |
tree | f1f5425889cc20e1e033aae5085172b9d35b8ad5 /doc/syntax/miscellaneous.rdoc | |
parent | c3584dfacce4d0f2058d8403de6fdce4fd4d686b (diff) |
Document defined? and global_variables handling of regexp global variables [ci skip]
Fixes [Bug #11304]
Diffstat (limited to 'doc/syntax/miscellaneous.rdoc')
-rw-r--r-- | doc/syntax/miscellaneous.rdoc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/syntax/miscellaneous.rdoc b/doc/syntax/miscellaneous.rdoc index 87ec059ae7..d5cfd3e474 100644 --- a/doc/syntax/miscellaneous.rdoc +++ b/doc/syntax/miscellaneous.rdoc @@ -83,6 +83,36 @@ Using the specific reflection methods such as instance_variable_defined? for instance variables or const_defined? for constants is less error prone than using +defined?+. ++defined?+ handles some regexp global variables specially based on whether +there is an active regexp match and how many capture groups there are: + + /b/ =~ 'a' + defined?($~) # => "global-variable" + defined?($&) # => nil + defined?($`) # => nil + defined?($') # => nil + defined?($+) # => nil + defined?($1) # => nil + defined?($2) # => nil + + /./ =~ 'a' + defined?($~) # => "global-variable" + defined?($&) # => "global-variable" + defined?($`) # => "global-variable" + defined?($') # => "global-variable" + defined?($+) # => nil + defined?($1) # => nil + defined?($2) # => nil + + /(.)/ =~ 'a' + defined?($~) # => "global-variable" + defined?($&) # => "global-variable" + defined?($`) # => "global-variable" + defined?($') # => "global-variable" + defined?($+) # => "global-variable" + defined?($1) # => "global-variable" + defined?($2) # => nil + == +BEGIN+ and +END+ +BEGIN+ defines a block that is run before any other code in the current file. |