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: 24f6997faf4e
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7990dbea53cc
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Apr 26, 2015

  1. Copy the full SHA
    6805f19 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    acca5e4 View commit details

Commits on Apr 27, 2015

  1. Merge pull request #812 from vais/kernel-array

    Kernel#Array fully compliant with rubyspec
    elia committed Apr 27, 2015
    Copy the full SHA
    7990dbe View commit details
Showing with 25 additions and 27 deletions.
  1. +15 −10 opal/corelib/kernel.rb
  2. +2 −0 spec/filters/bugs/kernel.rb
  3. +1 −0 spec/filters/unsupported/private_methods.rb
  4. +1 −0 spec/rubyspecs
  5. +6 −17 stdlib/native.rb
25 changes: 15 additions & 10 deletions opal/corelib/kernel.rb
Original file line number Diff line number Diff line change
@@ -56,20 +56,25 @@ def methods(all = true)
}
end

def Array(object, *args, &block)
def Array(object)
%x{
if (object == null || object === nil) {
var coerced;
if (object === nil) {
return [];
}
else if (#{object.respond_to? :to_ary}) {
return #{object.to_ary};
}
else if (#{object.respond_to? :to_a}) {
return #{object.to_a};
}
else {
return [object];
if (object.$$is_array) {
return object;
}
coerced = #{Opal.coerce_to?(object, Array, :to_ary)};
if (coerced !== nil) { return coerced; }
coerced = #{Opal.coerce_to?(object, Array, :to_a)};
if (coerced !== nil) { return coerced; }
return [object];
}
end

2 changes: 2 additions & 0 deletions spec/filters/bugs/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
opal_filter "Kernel" do
fails "Kernel.Array does not call #to_a on an Array" #something funky with the spec itself
fails "Kernel#Array does not call #to_a on an Array" #something funky with the spec itself
end
1 change: 1 addition & 0 deletions spec/filters/unsupported/private_methods.rb
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@

fails "Math#atanh is a private instance method"

fails "Kernel has private instance method Array()"
fails "Kernel#Integer is a private method"
fails "Kernel#Float is a private method"
fails "Kernel#format is a private method"
1 change: 1 addition & 0 deletions spec/rubyspecs
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ corelib/core/exception/new_spec
corelib/core/exception/reason_spec
corelib/core/exception/to_s_spec

corelib/core/kernel/Array_spec
corelib/core/kernel/comparison_spec
corelib/core/kernel/eql_spec
corelib/core/kernel/equal_spec
23 changes: 6 additions & 17 deletions stdlib/native.rb
Original file line number Diff line number Diff line change
@@ -141,24 +141,13 @@ def Native(obj)
end
end

alias_method :_Array, :Array

def Array(object, *args, &block)
%x{
if (object == null || object === nil) {
return [];
}
else if (#{native?(object)}) {
return #{Native::Array.new(object, *args, &block).to_a};
}
else if (#{object.respond_to? :to_ary}) {
return #{object.to_ary};
}
else if (#{object.respond_to? :to_a}) {
return #{object.to_a};
}
else {
return [object];
}
}
if native?(object)
return Native::Array.new(object, *args, &block).to_a
end
return _Array(object)
end
end