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: 5b857670d6ad
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8c1ce518ed99
Choose a head ref
  • 6 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 13, 2013

  1. Use Opal.coerce_to in String#+

    meh committed Nov 13, 2013
    Copy the full SHA
    13f8d2a View commit details
  2. Make String#chop compliant

    meh committed Nov 13, 2013
    Copy the full SHA
    e90e2e7 View commit details
  3. Copy the full SHA
    dfc3a61 View commit details
  4. Add Array::Wrapper#eql?

    meh committed Nov 13, 2013
    Copy the full SHA
    d6f38db View commit details
  5. Copy the full SHA
    01a9e10 View commit details
  6. Copy the full SHA
    8c1ce51 View commit details
Showing with 24 additions and 29 deletions.
  1. +4 −0 opal/core/array.rb
  2. +20 −29 opal/core/string.rb
4 changes: 4 additions & 0 deletions opal/core/array.rb
Original file line number Diff line number Diff line change
@@ -1550,6 +1550,10 @@ def ==(other)
@literal == other
end

def eql?(other)
@literal.eql?(other)
end

def to_a
@literal
end
49 changes: 20 additions & 29 deletions opal/core/string.rb
Original file line number Diff line number Diff line change
@@ -45,17 +45,9 @@ def *(count)
end

def +(other)
%x{
if (other._isString) {
return self + other;
}
}

unless other.respond_to? :to_str
raise TypeError, "no implicit conversion of #{other.class.name} into String"
end
other = Opal.coerce_to other, String, :to_str

`self + #{other.to_str}`
`self + #{other.to_s}`
end

def <=>(other)
@@ -66,7 +58,7 @@ def <=>(other)
}

if other.respond_to? :to_str
other = other.to_str
other = other.to_str.to_s

`self > other ? 1 : (self < other ? -1 : 0)`
end
@@ -147,17 +139,9 @@ def capitalize
end

def casecmp(other)
%x{
if (other._isString) {
return #{`self.toLowerCase()` <=> `other.toLowerCase()`};
}
}

unless other.respond_to? :to_str
raise TypeError, "no implicit conversion of #{other.class.name} into String"
end
other = Opal.coerce_to(other, String, :to_str).to_s

`self.toLowerCase()` <=> `#{other.to_str}.toLowerCase()`
`self.toLowerCase()` <=> `other.toLowerCase()`
end

def center(width, padstr = ' ')
@@ -178,13 +162,7 @@ def chars
def chomp(separator = $/)
return self if `separator === nil || self.length === 0`

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

separator = separator.to_str
end
separator = Opal.coerce_to!(separator, String, :to_str).to_s

%x{
if (separator === "\\n") {
@@ -206,7 +184,20 @@ def chomp(separator = $/)
end

def chop
`self.substr(0, self.length - 1)`
%x{
var length = self.length;
if (length <= 1) {
return "";
}
if (self.charAt(length - 1) === "\\n" && self.charAt(length - 2) === "\\r") {
return self.substr(0, length - 2);
}
else {
return self.substr(0, length - 1);
}
}
end

def chr