Skip to content

Commit

Permalink
NArray#each returns Enumerator if block is not given.
Browse files Browse the repository at this point in the history
  • Loading branch information
masa16 committed Jun 2, 2014
1 parent 9bdd1ef commit 67e8187
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions narray.c
Expand Up @@ -1096,18 +1096,22 @@ static VALUE
char *p;
void (*func)();

GetNArray(obj,ary);
if (rb_block_given_p()) {
GetNArray(obj,ary);

p = ary->ptr;
sz = na_sizeof[ary->type];
func = SetFuncs[NA_ROBJ][ary->type];
p = ary->ptr;
sz = na_sizeof[ary->type];
func = SetFuncs[NA_ROBJ][ary->type];

for ( i=ary->total; i-->0; ) {
(*func)( 1, &v, 0, p, 0 );
rb_yield(v);
p += sz;
for ( i=ary->total; i-->0; ) {
(*func)( 1, &v, 0, p, 0 );
rb_yield(v);
p += sz;
}
return Qnil;
} else {
return rb_funcall(obj, rb_intern("to_enum"), 0);
}
return Qnil;
}


Expand Down

0 comments on commit 67e8187

Please sign in to comment.