Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1a6726a25211
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b1b16ddb1ac0
Choose a head ref
  • 10 commits
  • 1 file changed
  • 1 contributor

Commits on Oct 23, 2013

  1. Cleanup Regexp.new

    meh committed Oct 23, 2013
    Copy the full SHA
    1624830 View commit details
  2. Make Regexp#=== compliant

    meh committed Oct 23, 2013
    Copy the full SHA
    c7574e6 View commit details
  3. Cleanup Regexp#=~

    meh committed Oct 23, 2013
    Copy the full SHA
    e8185ad View commit details
  4. Cleanup Regexp#inspect

    meh committed Oct 23, 2013
    Copy the full SHA
    194b415 View commit details
  5. Make Regexp#=~ compliant

    meh committed Oct 23, 2013
    Copy the full SHA
    c3607b4 View commit details
  6. Make Regexp#match compliant

    meh committed Oct 23, 2013
    Copy the full SHA
    e8da2c4 View commit details
  7. Cleanup Regexp#source

    meh committed Oct 23, 2013
    Copy the full SHA
    c3ef310 View commit details
  8. Cleanup Regexp#to_n

    meh committed Oct 23, 2013
    Copy the full SHA
    b6b3332 View commit details
  9. Copy the full SHA
    dff196b View commit details
  10. Copy the full SHA
    b1b16dd View commit details
Showing with 46 additions and 8 deletions.
  1. +46 −8 corelib/regexp.rb
54 changes: 46 additions & 8 deletions corelib/regexp.rb
Original file line number Diff line number Diff line change
@@ -10,20 +10,43 @@ def self.union(*parts)
end

def self.new(regexp, options = undefined)
`options? new RegExp(regexp, options) : new RegExp(regexp)`
`new RegExp(regexp, options)`
end

def ==(other)
`other.constructor == RegExp && #{self}.toString() === other.toString()`
end

def ===(str)
`#{self}.test(str)`
if `str._isString == null` && str.respond_to?(:to_str)
str = str.to_str
end

if `str._isString == null`
return false
end

`self.test(str)`
end

def =~(string)
if `string === nil`
$~ = $` = $' = nil

return
end

if `string._isString == null`
unless string.respond_to? :to_str
raise TypeError, "no implicit conversion of #{string.class} into String"
end

string = string.to_str
end

%x{
var re = #{self};
var re = self;
if (re.global) {
// should we clear it afterwards too?
re.lastIndex = 0;
@@ -49,18 +72,33 @@ def =~(string)
alias eql? ==

def inspect
`#{self}.toString()`
`self.toString()`
end

def match(string, pos = undefined)
if `string === nil`
$~ = $` = $' = nil

return
end

if `string._isString == null`
unless string.respond_to? :to_str
raise TypeError, "no implicit conversion of #{string.class} into String"
end

string = string.to_str
end

%x{
var re = #{self};
var re = self;
if (re.global) {
// should we clear it afterwards too?
re.lastIndex = 0;
}
else {
re = new RegExp(re.source, 'g' + (#{self}.multiline ? 'm' : '') + (#{self}.ignoreCase ? 'i' : ''));
re = new RegExp(re.source, 'g' + (re.multiline ? 'm' : '') + (re.ignoreCase ? 'i' : ''));
}
var result = re.exec(string);
@@ -75,12 +113,12 @@ def match(string, pos = undefined)
end

def source
`#{self}.source`
`self.source`
end

alias to_s source

def to_n
`#{self}.valueOf()`
`self.valueOf()`
end
end