mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enum.c: Make Enumerable#chunk with no block return
an Enumerator [#2172] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
468301b984
commit
69846644d2
4 changed files with 15 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Oct 5 03:24:55 2016 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* enum.c: Make Enumerable#chunk with no block return
|
||||||
|
an Enumerator [#2172]
|
||||||
|
|
||||||
Wed Oct 5 01:19:45 2016 NAKAMURA Usaku <usa@ruby-lang.org>
|
Wed Oct 5 01:19:45 2016 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
|
* internal.h (ST2FIX): new macro to convert st_index_t to Fixnum.
|
||||||
|
|
2
NEWS
2
NEWS
|
@ -42,6 +42,8 @@ with all sufficient information, see the ChangeLog file or Redmine
|
||||||
|
|
||||||
* Enumerable#sum [Feature #12217]
|
* Enumerable#sum [Feature #12217]
|
||||||
* Enumerable#uniq [Feature #11090]
|
* Enumerable#uniq [Feature #11090]
|
||||||
|
* Enumerable#chunk called without a block now return an Enumerator
|
||||||
|
[Feature #2172]
|
||||||
|
|
||||||
* Enumerator::Lazy
|
* Enumerator::Lazy
|
||||||
|
|
||||||
|
|
4
enum.c
4
enum.c
|
@ -2995,14 +2995,14 @@ chunk_i(RB_BLOCK_CALL_FUNC_ARGLIST(yielder, enumerator))
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* If no block is given, an enumerator to `chunk` is returned instead.
|
||||||
*/
|
*/
|
||||||
static VALUE
|
static VALUE
|
||||||
enum_chunk(VALUE enumerable)
|
enum_chunk(VALUE enumerable)
|
||||||
{
|
{
|
||||||
VALUE enumerator;
|
VALUE enumerator;
|
||||||
|
|
||||||
if (!rb_block_given_p())
|
RETURN_SIZED_ENUMERATOR(enumerable, 0, 0, enum_size);
|
||||||
rb_raise(rb_eArgError, "no block given");
|
|
||||||
|
|
||||||
enumerator = rb_obj_alloc(rb_cEnumerator);
|
enumerator = rb_obj_alloc(rb_cEnumerator);
|
||||||
rb_ivar_set(enumerator, rb_intern("chunk_enumerable"), enumerable);
|
rb_ivar_set(enumerator, rb_intern("chunk_enumerable"), enumerable);
|
||||||
|
|
|
@ -611,6 +611,12 @@ class TestEnumerable < Test::Unit::TestCase
|
||||||
|
|
||||||
e = @obj.chunk {|elt| :_foo }
|
e = @obj.chunk {|elt| :_foo }
|
||||||
assert_raise(RuntimeError) { e.to_a }
|
assert_raise(RuntimeError) { e.to_a }
|
||||||
|
|
||||||
|
e = @obj.chunk.with_index {|elt, i| elt - i }
|
||||||
|
assert_equal([[1, [1, 2, 3]],
|
||||||
|
[-2, [1, 2]]], e.to_a)
|
||||||
|
|
||||||
|
assert_equal(4, (0..3).chunk.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_slice_before
|
def test_slice_before
|
||||||
|
|
Loading…
Add table
Reference in a new issue