Fix the return value of Integer#downto
called with a block
As the document states, it should return `self`, not `nil`. Fix up of f4b313f7338f5fbe37f73aae29f70aeb474f7f5b.
This commit is contained in:
parent
70be2f4731
commit
0fe024d048
@ -243,7 +243,7 @@ class Integer
|
|||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# downto(limit) {|i| ... } -> self
|
# downto(limit) {|i| ... } -> self
|
||||||
# downto(limit) -> enumerator
|
# downto(limit) -> enumerator
|
||||||
#
|
#
|
||||||
# Calls the given block with each integer value from +self+ down to +limit+;
|
# Calls the given block with each integer value from +self+ down to +limit+;
|
||||||
# returns +self+:
|
# returns +self+:
|
||||||
@ -268,6 +268,7 @@ class Integer
|
|||||||
yield from
|
yield from
|
||||||
from = from.pred
|
from = from.pred
|
||||||
end
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
|
@ -282,31 +282,31 @@ class TestInteger < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_upto
|
def test_upto
|
||||||
a = []
|
a = []
|
||||||
1.upto(3) {|x| a << x }
|
assert_equal(1, 1.upto(3) {|x| a << x })
|
||||||
assert_equal([1, 2, 3], a)
|
assert_equal([1, 2, 3], a)
|
||||||
|
|
||||||
a = []
|
a = []
|
||||||
1.upto(0) {|x| a << x }
|
assert_equal(1, 1.upto(0) {|x| a << x })
|
||||||
assert_equal([], a)
|
assert_equal([], a)
|
||||||
|
|
||||||
y = 2**30 - 1
|
y = 2**30 - 1
|
||||||
a = []
|
a = []
|
||||||
y.upto(y+2) {|x| a << x }
|
assert_equal(y, y.upto(y+2) {|x| a << x })
|
||||||
assert_equal([y, y+1, y+2], a)
|
assert_equal([y, y+1, y+2], a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_downto
|
def test_downto
|
||||||
a = []
|
a = []
|
||||||
-1.downto(-3) {|x| a << x }
|
assert_equal(-1, -1.downto(-3) {|x| a << x })
|
||||||
assert_equal([-1, -2, -3], a)
|
assert_equal([-1, -2, -3], a)
|
||||||
|
|
||||||
a = []
|
a = []
|
||||||
1.downto(2) {|x| a << x }
|
assert_equal(1, 1.downto(2) {|x| a << x })
|
||||||
assert_equal([], a)
|
assert_equal([], a)
|
||||||
|
|
||||||
y = -(2**30)
|
y = -(2**30)
|
||||||
a = []
|
a = []
|
||||||
y.downto(y-2) {|x| a << x }
|
assert_equal(y, y.downto(y-2) {|x| a << x })
|
||||||
assert_equal([y, y-1, y-2], a)
|
assert_equal([y, y-1, y-2], a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user