[#115244] [Ruby master Feature#19987] add sample method to Range — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19987 has been reported by horv77@protonmail.com (Andras Horvath).
6 messages
2023/11/05
[#115247] [Ruby master Feature#19988] AI for inner code behavior analysis at runtime — "horv77@... (Andras Horvath) via ruby-core" <ruby-core@...>
Issue #19988 has been reported by horv77@protonmail.com (Andras Horvath).
3 messages
2023/11/05
[#115404] Ruby 3.2.2 - rbconfig.rb's MAKEFILE_CONFIG — Jay Mav via ruby-core <ruby-core@...>
Hello Ruby Dev Team,
4 messages
2023/11/17
[ruby-core:115369] [Ruby master Bug#11808] Different behavior between Enumerable#grep and Array#grep
From:
"noelrap (Noel Rappin) via ruby-core" <ruby-core@...>
Date:
2023-11-13 19:27:08 UTC
List:
ruby-core #115369
Issue #11808 has been updated by noelrap (Noel Rappin).
This appears to be fixed in 3.3.0dev as of Nov 2023,
``` ruby
irb(main):001* class Test
irb(main):002* include Enumerable
irb(main):003* def each
irb(main):004* return enum_for(:each) unless block_given?
irb(main):005* yield "Hello"
irb(main):006* yield "World"
irb(main):007* end
irb(main):008> end
=> :each
irb(main):009>
irb(main):010> enum = Test.new
=> #<Test:0x0000000102ba5038>
irb(main):011> array = ["Hello", "World"]
=> ["Hello", "World"]
irb(main):012>
irb(main):013> enum.grep(/^(.)/) {$1}
=> ["H", "W"]
```
However, it was still broken in 3.2.2. It's not clear to me when the behavior changed.
----------------------------------------
Bug #11808: Different behavior between Enumerable#grep and Array#grep
https://bugs.ruby-lang.org/issues/11808#change-105298
* Author: BenOlive (Ben Olive)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Regex special global variables are available within the block for `Array#grep`, but are nil within the block for `Enumerable#grep`.
Here is an example that explains it better:
~~~ruby
class Test
include Enumerable
def each
return enum_for(:each) unless block_given?
yield "Hello"
yield "World"
end
end
enum = Test.new
array = ["Hello", "World"]
enum.grep(/^(.)/) {$1} # => [nil, nil]
array.grep(/^(.)/) {$1} # => ["H", "W"]
~~~
Tested on 2.0.0, 2.1.5, & 2.2.2
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/