* enumerator.c (lazy_grep_func): should use === instead of =~, as
well as Enumerable#grep git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8f30190dfe
commit
cb1d290886
@ -1,3 +1,8 @@
|
|||||||
|
Wed Mar 14 10:44:35 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* enumerator.c (lazy_grep_func): should use === instead of =~, as
|
||||||
|
well as Enumerable#grep
|
||||||
|
|
||||||
Wed Mar 14 08:15:54 2012 Shugo Maeda <shugo@ruby-lang.org>
|
Wed Mar 14 08:15:54 2012 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* enumerator.c (lazy_zip_func): use each for non-Array objects.
|
* enumerator.c (lazy_zip_func): use each for non-Array objects.
|
||||||
|
@ -103,7 +103,8 @@
|
|||||||
*/
|
*/
|
||||||
VALUE rb_cEnumerator;
|
VALUE rb_cEnumerator;
|
||||||
VALUE rb_cLazy;
|
VALUE rb_cLazy;
|
||||||
static ID id_rewind, id_each, id_new, id_initialize, id_yield, id_call, id_next, id_result, id_lazy;
|
static ID id_rewind, id_each, id_new, id_initialize, id_yield, id_call;
|
||||||
|
static ID id_eqq, id_next, id_result, id_lazy;
|
||||||
static VALUE sym_each;
|
static VALUE sym_each;
|
||||||
|
|
||||||
VALUE rb_eStopIteration;
|
VALUE rb_eStopIteration;
|
||||||
@ -1377,7 +1378,7 @@ static VALUE
|
|||||||
lazy_grep_func(VALUE val, VALUE m, int argc, VALUE *argv)
|
lazy_grep_func(VALUE val, VALUE m, int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
VALUE element = argv[1];
|
VALUE element = argv[1];
|
||||||
VALUE result = rb_funcall(m, rb_intern("=~"), 1, element);
|
VALUE result = rb_funcall(m, id_eqq, 1, element);
|
||||||
|
|
||||||
if (RTEST(result)) {
|
if (RTEST(result)) {
|
||||||
return rb_funcall(argv[0], id_yield, 1, element);
|
return rb_funcall(argv[0], id_yield, 1, element);
|
||||||
@ -1530,6 +1531,7 @@ Init_Enumerator(void)
|
|||||||
id_next = rb_intern("next");
|
id_next = rb_intern("next");
|
||||||
id_result = rb_intern("result");
|
id_result = rb_intern("result");
|
||||||
id_lazy = rb_intern("lazy");
|
id_lazy = rb_intern("lazy");
|
||||||
|
id_eqq = rb_intern("===");
|
||||||
sym_each = ID2SYM(id_each);
|
sym_each = ID2SYM(id_each);
|
||||||
|
|
||||||
InitVM(Enumerator);
|
InitVM(Enumerator);
|
||||||
|
@ -118,6 +118,8 @@ class TestLazyEnumerator < Test::Unit::TestCase
|
|||||||
assert_equal('f', a.current)
|
assert_equal('f', a.current)
|
||||||
assert_equal('c', a.lazy.grep(/c/).first)
|
assert_equal('c', a.lazy.grep(/c/).first)
|
||||||
assert_equal('c', a.current)
|
assert_equal('c', a.current)
|
||||||
|
assert_equal(%w[a e], a.grep(proc {|x| /[aeiou]/ =~ x}))
|
||||||
|
assert_equal(%w[a e], a.lazy.grep(proc {|x| /[aeiou]/ =~ x}).to_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_zip
|
def test_zip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user