diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-10 07:30:47 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-10 07:30:47 +0000 |
| commit | 453f94c2b2d209050d2aabd1eabf1093b9293b35 (patch) | |
| tree | 81b2b9c7a8397620ba1c959e12f6778b6d8cb50a | |
| parent | bbbd594c3c6da43c08332c2e63737f8e8fe4846e (diff) | |
* eval.c (rb_f_loop): Return an enumerator if no block is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | eval.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_iterator.rb | 21 |
4 files changed, 32 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Wed Mar 10 16:12:21 2010 Akinori MUSHA <knu@iDaemons.org> + + * eval.c (rb_f_loop): Return an enumerator if no block is given. + Tue Mar 9 22:58:59 2010 NAKAMURA, Hiroshi <nahi@ruby-lang.org> * ext/openssl/ossl_config.c: defined own IMPLEMENT_LHASH_DOALL_ARG_FN_098 @@ -38,6 +38,10 @@ with all sufficient information, see the ChangeLog file. === Library updates (outstanding ones only) +* global functions + + * Return an enumerator if no block is given. + * builtin classes * Array#try_convert() @@ -5319,8 +5319,10 @@ loop_i() */ static VALUE -rb_f_loop() +rb_f_loop(self) + VALUE self; { + RETURN_ENUMERATOR(self, 0, 0); rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0); return Qnil; /* dummy */ } diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 2cd48b29a4..60c589efef 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -474,4 +474,25 @@ class TestIterator < Test::Unit::TestCase def test_block_given_within_iterator assert_equal(["b"], ["a", "b", "c"].grep(IterString.new("b")) {|s| s}) end + + def test_loop + i = 0 + loop { + i = 1 + break + } + assert_equal(1, i) + + i = 0 + loop { + i += 1 + break if i > 1 + } + assert_equal(2, i) + + assert_nothing_raised { + x = loop + assert_kind_of(Enumerable, x) + } + end end |
