Sha256: ed04e98f33d551e16834712b569b5aafca82b7d64d5410e0daeb1e53b52d5bfa

Contents?: true

Size: 479 Bytes

Versions: 20

Compression:

Stored size: 479 Bytes

Contents

class String

  # Turns a string into a regular expression.
  #
  #   "a?".to_re  #=> /a?/
  #
  # CREDIT: Trans

  def to_re(esc=false)
    Regexp.new((esc ? Regexp.escape(self) : self))
  end

  # Turns a string into a regular expression.
  # By default it will escape all characters.
  # Use <tt>false</tt> argument to turn off escaping.
  #
  #   "[".to_rx  #=> /\[/
  #
  # CREDIT: Trans

  def to_rx(esc=true)
    Regexp.new((esc ? Regexp.escape(self) : self))
  end

end

Version data entries

20 entries across 19 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/to_re.rb
facets-3.1.0 lib/core/facets/string/to_re.rb
facets-3.0.0 lib/core/facets/string/to_re.rb
facets-2.9.3 lib/core/facets/string/to_re.rb
facets-2.9.2 lib/core/facets/string/to_re.rb
facets-2.9.2 src/core/facets/string/to_re.rb
facets-2.9.1 lib/core/facets/string/to_re.rb
facets-2.9.0 lib/core/facets/string/to_re.rb
facets-2.9.0.pre.2 lib/core/facets/string/to_re.rb
facets-2.9.0.pre.1 lib/core/facets/string/to_re.rb
facets-2.8.4 lib/core/facets/string/to_re.rb
facets-2.8.3 lib/core/facets/string/to_re.rb
facets-2.8.2 lib/core/facets/string/to_re.rb
facets-2.8.1 lib/core/facets/string/to_re.rb
facets-2.8.0 lib/core/facets/string/to_re.rb
facets-2.7.0 lib/core/facets/string/to_re.rb
facets-2.6.0 lib/core/facets/string/to_re.rb
facets-2.5.0 lib/core/facets/string/to_re.rb
facets-2.5.1 lib/core/facets/string/to_re.rb
facets-2.5.2 lib/core/facets/string/to_re.rb