summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-10 07:30:47 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-10 07:30:47 +0000
commit453f94c2b2d209050d2aabd1eabf1093b9293b35 (patch)
tree81b2b9c7a8397620ba1c959e12f6778b6d8cb50a
parentbbbd594c3c6da43c08332c2e63737f8e8fe4846e (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--ChangeLog4
-rw-r--r--NEWS4
-rw-r--r--eval.c4
-rw-r--r--test/ruby/test_iterator.rb21
4 files changed, 32 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 74e6ea3b01..87a8fe3222 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/NEWS b/NEWS
index 7f5641f8ee..57080c6ac1 100644
--- a/NEWS
+++ b/NEWS
@@ -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()
diff --git a/eval.c b/eval.c
index f8a667bbf6..1d129a5ae9 100644
--- a/eval.c
+++ b/eval.c
@@ -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