From: Joseph Jones Date: 2015-12-17T21:13:22-07:00 Subject: [ruby-core:72342] [Ruby trunk - Bug #11808] [Open] DIfferent behavior between Enumerable#grep and Array#grep --567387e2_51088277_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 11, 2015 at 16:53= :02 MST, ben.olive=40gatech.edu wrote:Issue =2311808 has been reported by= Ben Olive.----------------------------------------Bug =2311808: DIfferen= t behavior between Enumerable=23grep and Array=23grephttps://bugs.ruby-la= ng.org/issues/11808* Author: Ben Olive* Status: Open* Priority: Normal* A= ssignee: * ruby -v: 2.2.2* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: U= NKNOWN----------------------------------------Regex special global variab= les are available within the block for Array=23grep, but are nil within t= he block for Enumerable=23grep.Here is an example that explains it better= :=7E=7E=7Eclass Test include Enumerable def each return enum=5Ffor(:each)= unless block=5Fgiven=3F yield =22Hello=22 yield =22World=22 endendenum =3D= Test.newarray =3D =5B=22Hello=22, =22World=22=5Denum.grep(/=5E(.)/) =7B=24= 1=7D =23 =3D> =5Bnil, nil=5Darray.grep(/=5E(.)/) =7B=241=7D =23 =3D> =5B=22= H=22, =22W=22=5D=7E=7E=7ETested on 2.0.0, 2.1.5, & 2.2.2-- https://bugs.r= uby-lang.org/ --567387e2_51088277_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 11, 2015 at 16:53:02 MST, ben.olive=40gatech.edu wrote:
<= blockquote type=3D=22cite=22 style=3D=22border-left-style:solid;border-wi= dth:1px;margin-left:0px;padding-left:10px;=22>Issue =2311808 has been rep= orted by Ben Olive.

----------------------------------------Bug =2311808: DIfferent behavior between Enumerable=23grep and Array=23= grep
https://bugs.ruby-lang.org/issues/11808

* Author: Be= n Olive
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UN= KNOWN
----------------------------------------
Regex special gl= obal variables are available within the block for Array=23grep, but are n= il within the block for Enumerable=23grep.

Here is an example = that explains it better:

=7E=7E=7E
class Test
incl= ude Enumerable
def each
return enum=5Ffor(:each) unless b= lock=5Fgiven=3F
yield =22Hello=22
yield =22World=22
end
end

enum =3D Test.new
array =3D =5B=22Hello=22= , =22World=22=5D

enum.grep(/=5E(.)/) =7B=241=7D =23 =3D> =5Bni= l, nil=5D
array.grep(/=5E(.)/) =7B=241=7D =23 =3D> =5B=22H=22, =22W=22= =5D
=7E=7E=7E

Tested on 2.0.0, 2.1.5, & 2.2.2

=

--
https://bugs.ruby-lang.org/
=
--567387e2_51088277_16c--