mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mrblib/array.rb: Array#<=> to handle NoMethodError exception.
Array element may not respond to `<=>` method.
This commit is contained in:
+8
-4
@@ -167,10 +167,14 @@ class Array
|
||||
n = other.size
|
||||
len = n if len > n
|
||||
i = 0
|
||||
while i < len
|
||||
n = (self[i] <=> other[i])
|
||||
return n if n.nil? || n != 0
|
||||
i += 1
|
||||
begin
|
||||
while i < len
|
||||
n = (self[i] <=> other[i])
|
||||
return n if n.nil? || n != 0
|
||||
i += 1
|
||||
end
|
||||
rescue NoMethodError
|
||||
return nil
|
||||
end
|
||||
len = self.size - other.size
|
||||
if len == 0
|
||||
|
||||
Reference in New Issue
Block a user