diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-04 03:34:52 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-04 03:34:52 +0000 |
commit | dcb37d06395d996b046b755d2219c4accaac0b5f (patch) | |
tree | a3df2019683781e87946d01809b6c2975fec2555 | |
parent | e59017354782c7cf599af39c6725486cca03297d (diff) | |
download | ruby-dcb37d06395d996b046b755d2219c4accaac0b5f.tar.gz |
range.c: support to make beginless arithmetic sequences
* range.c (range_step): fix the guard condition so that a beginless
range can be turned into a beginless arithmetic sequence.
* test/ruby/test_range.rb (test_step): add assertions for the above
change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67433 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | range.c | 4 | ||||
-rw-r--r-- | test/ruby/test_range.rb | 2 |
2 files changed, 5 insertions, 1 deletions
@@ -397,7 +397,9 @@ range_step(int argc, VALUE *argv, VALUE range) step = (!rb_check_arity(argc, 0, 1) ? INT2FIX(1) : argv[0]); if (!rb_block_given_p()) { - if (rb_obj_is_kind_of(b, rb_cNumeric) && (NIL_P(e) || rb_obj_is_kind_of(e, rb_cNumeric))) { + const VALUE b_num_p = rb_obj_is_kind_of(b, rb_cNumeric); + const VALUE e_num_p = rb_obj_is_kind_of(e, rb_cNumeric); + if ((b_num_p && (NIL_P(e) || e_num_p)) || (NIL_P(b) && e_num_p)) { return rb_arith_seq_new(range, ID2SYM(rb_frame_this_func()), argc, argv, range_step_size, b, e, step, EXCL(range)); } diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index b631c7d2b9..b704f8e182 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -226,6 +226,8 @@ class TestRange < Test::Unit::TestCase assert_kind_of(Enumerator::ArithmeticSequence, (0..10).step(2)) assert_kind_of(Enumerator::ArithmeticSequence, (0..10).step(0.5)) assert_kind_of(Enumerator::ArithmeticSequence, (10..0).step(-1)) + assert_kind_of(Enumerator::ArithmeticSequence, (..10).step(2)) + assert_kind_of(Enumerator::ArithmeticSequence, (1..).step(2)) assert_raise(ArgumentError) { (0..10).step(0) { } } assert_raise(ArgumentError) { (0..).step(-1) { } } |