Commit c326f065 authored by go.kikuta's avatar go.kikuta

array.rb: refactor some code

parent 05625cd6
...@@ -16,7 +16,7 @@ class Array ...@@ -16,7 +16,7 @@ class Array
while idx < length and length <= self.length and length = self.length-1 while idx < length and length <= self.length and length = self.length-1
elm = self[idx += 1] elm = self[idx += 1]
unless elm unless elm
if elm == nil and length >= self.length if elm.nil? and length >= self.length
break break
end end
end end
...@@ -50,9 +50,7 @@ class Array ...@@ -50,9 +50,7 @@ class Array
def collect!(&block) def collect!(&block)
return to_enum :collect! unless block_given? return to_enum :collect! unless block_given?
self.each_index{|idx| self.each_index { |idx| self[idx] = block.call(self[idx]) }
self[idx] = block.call(self[idx])
}
self self
end end
...@@ -72,7 +70,7 @@ class Array ...@@ -72,7 +70,7 @@ class Array
self.clear self.clear
if size > 0 if size > 0
self[size - 1] = nil # allocate self[size - 1] = nil # allocate
idx = 0 idx = 0
while idx < size while idx < size
...@@ -158,14 +156,11 @@ class Array ...@@ -158,14 +156,11 @@ class Array
len = self.size len = self.size
n = other.size n = other.size
if len > n len = n if len > n
len = n
end
i = 0 i = 0
while i < len while i < len
n = (self[i] <=> other[i]) n = (self[i] <=> other[i])
return n if n == nil return n if n.nil? || n != 0
return n if n != 0
i += 1 i += 1
end end
len = self.size - other.size len = self.size - other.size
...@@ -185,7 +180,7 @@ class Array ...@@ -185,7 +180,7 @@ class Array
self.delete_at(i) self.delete_at(i)
ret = key ret = key
end end
if ret == nil && block if ret.nil? && block
block.call block.call
else else
ret ret
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment