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

Commits on Nov 11, 2013

  1. Make Array#== compliant

    meh committed Nov 11, 2013

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    929eae6 View commit details
  2. Implement Array#eql?

    meh committed Nov 11, 2013
    Copy the full SHA
    0abf78b View commit details
  3. Copy the full SHA
    60b25bf View commit details
  4. Copy the full SHA
    082b402 View commit details
  5. Copy the full SHA
    1a4f081 View commit details
  6. Copy the full SHA
    3980f91 View commit details
Showing with 61 additions and 13 deletions.
  1. +60 −13 opal/core/array.rb
  2. +1 −0 spec/filters/unsupported/float.rb
73 changes: 60 additions & 13 deletions opal/core/array.rb
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ def &(other)
if Array === other
other = other.to_a
else
other = Opal.coerce_to other, Array, :to_ary
other = Opal.coerce_to(other, Array, :to_ary).to_a
end

%x{
@@ -124,7 +124,7 @@ def +(other)
if Array === other
other = other.to_a
else
other = Opal.coerce_to other, Array, :to_ary
other = Opal.coerce_to(other, Array, :to_ary).to_a
end

`self.concat(other)`
@@ -134,7 +134,7 @@ def -(other)
if Array === other
other = other.to_a
else
other = Opal.coerce_to other, Array, :to_ary
other = Opal.coerce_to(other, Array, :to_ary).to_a
end

return [] if `self.length === 0`
@@ -170,7 +170,7 @@ def <=>(other)
if Array === other
other = other.to_a
elsif other.respond_to? :to_ary
other = other.to_ary
other = other.to_ary.to_a
else
return
end
@@ -197,15 +197,18 @@ def <=>(other)
end

def ==(other)
return false unless Array === other
return true if `self === other`

unless Array === other
return false unless other.respond_to? :to_ary
return other == self
end

other = other.to_a

%x{
if (self.length !== other.length) {
return false;
}
return false unless `self.length === other.length`

%x{
for (var i = 0, length = self.length; i < length; i++) {
var a = self[i],
b = other[i];
@@ -214,7 +217,7 @@ def ==(other)
continue;
}
if (!(#{`a` == `b`})) {
if (!#{`a` == `b`}) {
return false;
}
}
@@ -401,7 +404,19 @@ def clear
end

def clone
`self.slice()`
copy = []
copy.initialize_clone(self)
copy
end

def dup
copy = []
copy.initialize_dup(self)
copy
end

def initialize_copy(other)
replace other
end

def collect(&block)
@@ -477,7 +492,7 @@ def concat(other)
if Array === other
other = other.to_a
else
other = Opal.coerce_to other, Array, :to_ary
other = Opal.coerce_to(other, Array, :to_ary).to_a
end

%x{
@@ -593,6 +608,32 @@ def empty?
`self.length === 0`
end

def eql?(other)
return true if `self === other`
return false unless Array === other

other = other.to_a

return false unless `self.length === other.length`

%x{
for (var i = 0, length = self.length; i < length; i++) {
var a = self[i],
b = other[i];
if (a._isArray && b._isArray && (a === self)) {
continue;
}
if (!#{`a`.eql? `b`}) {
return false;
}
}
}

true
end

def fetch(index, defaults = undefined, &block)
%x{
var original = index;
@@ -1009,6 +1050,12 @@ def reject!(&block)
end

def replace(other)
if Array === other
other = other.to_a
else
other = Opal.coerce_to(other, Array, :to_ary).to_a
end

%x{
self.splice(0, self.length);
self.push.apply(self, other);
@@ -1260,7 +1307,7 @@ def transpose
if Array === row
row = row.to_a
else
row = Opal.coerce_to row, Array, :to_ary
row = Opal.coerce_to(row, Array, :to_ary).to_a
end

max ||= `row.length`
1 change: 1 addition & 0 deletions spec/filters/unsupported/float.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
opal_filter "Float" do
fails "Array#inspect represents a recursive element with '[...]'"
fails "Array#to_s represents a recursive element with '[...]'"
fails "Array#eql? returns false if any corresponding elements are not #eql?"
end