Class: Regexp
- Inherits:
-
Object
- Object
- Regexp
- Defined in:
- lib/core/facets/regexp/arity.rb,
lib/core/facets/regexp/to_re.rb,
lib/core/facets/regexp/op_or.rb,
lib/core/facets/regexp/op_add.rb,
lib/core/facets/regexp/multiline.rb,
lib/core-uncommon/facets/regexp/op_or.rb
Instance Method Summary (collapse)
-
- (Object) +(other)
Add regular expressions.
-
- (Object) arity
Returns the number of backreferencing subexpressions.
-
- (Boolean) multiline?
Is a regular expression multiline?.
-
- (Object) to_re(esc = false)
Simply returns itself.
-
- (Object) to_regexp
Like #to_re, but following Ruby's formal definitions, only a Regular expression type object will respond to this.
-
- (Object) |(arg)
Operator form of `Regexp.union`:.
Instance Method Details
- (Object) +(other)
Add regular expressions.
/a/ + /b/ == /(?-mix:a)(?-mix:b)/
Functionally equivalent to:
/ab/
CREDIT: Tyler Rick
12 13 14 15 |
# File 'lib/core/facets/regexp/op_add.rb', line 12 def +(other) other = Regexp.escape(other) if other.is_a?(String) /#{self}#{other}/ end |
- (Object) arity
Returns the number of backreferencing subexpressions.
/(a)(b)(c)/.arity #=> 3
/(a(b(c)))/.arity #=> 3
Note that this is not perfect, especially with regards to x and embedded comments.
CREDIT: Trans
13 14 15 |
# File 'lib/core/facets/regexp/arity.rb', line 13 def arity source.scan( /(?!\\)[(](?!\?[#=:!>-imx])/ ).length end |
- (Boolean) multiline?
Is a regular expression multiline?
/x/.multiline? #=> false
/x/m.multiline? #=> true
8 9 10 |
# File 'lib/core/facets/regexp/multiline.rb', line 8 def multiline? & MULTILINE == MULTILINE end |
- (Object) to_re(esc = false)
Simply returns itself. Helpful when converting strings to regular expressions, where regexp might occur as well --in the same vien as using #to_s on symbols. The parameter is actaully a dummy parameter to coincide with String#to_re.
/abc/.to_re #=> /abc/
CREDIT: Trans
24 25 26 |
# File 'lib/core/facets/regexp/to_re.rb', line 24 def to_re(esc=false) self # Of course, things really should know how to say "I" ;) end |
- (Object) to_regexp
Like #to_re, but following Ruby's formal definitions, only a Regular expression type object will respond to this.
Note that to be of much real use this should be defined in core Ruby.
CREDIT: Florian Gross
10 11 12 |
# File 'lib/core/facets/regexp/to_re.rb', line 10 def to_regexp self end |
- (Object) |(arg)
Operator form of `Regexp.union`:
/a/ | /b/ #=> /(a|b)/
NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.
12 13 14 |
# File 'lib/core/facets/regexp/op_or.rb', line 12 def |(arg) Regexp.union(self, arg.is_a?(Regexp) ? arg : arg.to_s) end |