Sha256: 7b3ac8ff0040af3fc1d5709a7607be9d2e0ddca07ea09859d249e877832b4a9b
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
class Regexp < `RegExp` def self.escape(string) `string.replace(/([.*+?^=!:${}()|[\]\\/\\])/g, '\\$1')` end def self.new(string, options = undefined) `new RegExp(string, options)` end def ==(other) `other.constructor == RegExp && #{self}.toString() === other.toString()` end def ===(obj) `#{self}.test(obj)` end def =~(string) %x{ var result = #{self}.exec(string); if (result) { var matchdata = #{MatchData}; result.$k = matchdata; result.$m = matchdata.$m_tbl; #{$~ = `result`}; } else { #{$~ = nil}; } return result ? result.index : nil; } end alias eql? == def inspect `#{self}.toString()` end def match(pattern) %x{ var result = #{self}.exec(pattern); if (result) { var matchdata = #{MatchData}; result.$k = matchdata; result.$m = matchdata.$m_tbl; return #{$~ = `result`}; } else { return #{$~ = nil}; } } end def to_s `#{self}.source` end end class MatchData def [](idx) `#{self}[idx]` end def inspect "#<MatchData #{self[0].inspect}>" end def to_a `#{self}.slice()` end def to_s self[0] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
opal-0.3.21 | core/regexp.rb |