Skip to content
Permalink
Browse files

Merge pull request #733 from kostya/array

fix Kernel#Array
  • Loading branch information
alex committed May 24, 2013
2 parents e48fe7e + d2c9312 commit 9a203d784b52b9dc37e2d177016efa12f1e02d99
Showing with 10 additions and 14 deletions.
  1. +4 −4 lib-topaz/kernel.rb
  2. +0 −10 spec/tags/core/kernel/Array_tags.txt
  3. +6 −0 topaz/modules/topaz.py
@@ -20,10 +20,10 @@ def <=>(other)
end

def Array(arg)
if arg.respond_to? :to_ary
arg.to_ary
elsif arg.respond_to? :to_a
arg.to_a
if ary = Topaz.try_convert_type(arg, Array, :to_ary)
ary
elsif arg.respond_to?(:to_a) && ary = Topaz.try_convert_type(arg, Array, :to_a)
ary
else
[arg]
end
@@ -1,11 +1 @@
fails:Kernel has private instance method Array()
fails:Kernel.Array does not call #to_ary on an Array
fails:Kernel.Array calls #to_a if #to_ary returns nil
fails:Kernel.Array returns an Array containing the argument if #to_a returns nil
fails:Kernel.Array raises a TypeError if #to_ary does not return an Array
fails:Kernel.Array raises a TypeError if #to_a does not return an Array
fails:Kernel#Array does not call #to_ary on an Array
fails:Kernel#Array calls #to_a if #to_ary returns nil
fails:Kernel#Array returns an Array containing the argument if #to_a returns nil
fails:Kernel#Array raises a TypeError if #to_ary does not return an Array
fails:Kernel#Array raises a TypeError if #to_a does not return an Array
@@ -28,6 +28,12 @@ def method_convert_type(self, space, w_obj, w_type, method):
raise space.error(space.w_TypeError, "type argument must be a class")
return space.convert_type(w_obj, w_type, method)

@moduledef.function("try_convert_type", method="symbol")
def method_try_convert_type(self, space, w_obj, w_type, method):
if not isinstance(w_type, W_ClassObject):
raise space.error(space.w_TypeError, "type argument must be a class")
return space.convert_type(w_obj, w_type, method, raise_error=False)

@moduledef.function("compare")
def method_compare(self, space, w_a, w_b, block=None):
return space.compare(w_a, w_b, block)

0 comments on commit 9a203d7

Please sign in to comment.
You can’t perform that action at this time.