Class: Sidewalk::Regexp

Inherits:
REGEXP_BASE
  • Object
show all
Defined in:
lib/sidewalk/regexp.rb

Overview

A Regexp class that supports named captures.

This class exists just to give a portable class name to refer to.

  • On Ruby 1.9, this inherits ::Regexp.

  • On Ruby 1.8, this inherits Oniguruma::ORegexp (which is basically the same library that Ruby 1.9 uses for ::Regexp)

Examples:

Using named captures

regexp = Sidewalk::Regexp.new('(?<foo>bar)')
match = regexp.match(regexp)
match['foo'].should == 'bar'

Class Method Summary collapse

Class Method Details

.native?Boolean

Whether we’re using ::Regexp

Inverse of #native?.

Returns:

  • (Boolean)


46
47
48
# File 'lib/sidewalk/regexp.rb', line 46

def self.native?
  !self.oniguruma?
end

.oniguruma?Boolean

Whether we’re using Onigirumua::ORegexp.

Inverse of #native?.

Returns:

  • (Boolean)


39
40
41
# File 'lib/sidewalk/regexp.rb', line 39

def self.oniguruma?
  Sidewalk::REGEXP_USING_ONIGURUMA
end