[#111472] [Ruby master Bug#19274] Error installing ruby 3.2.0 on RH 8 — "aalllop (Alberto Allegue) via ruby-core" <ruby-core@...>
Issue #19274 has been reported by aalllop (Alberto Allegue).
5 messages
2022/12/28
[#111508] Data support for versions before 3.2.0 — Eustáquio Rangel via ruby-core <ruby-core@...>
I was wondering that every piece of code (gems, etc) that use the new Data =
3 messages
2022/12/29
[ruby-core:111366] [Ruby master Feature#13890] Allow a regexp as an argument to 'count', to count more interesting things than single characters
From:
"shan (Shannon Skipper) via ruby-core" <ruby-core@...>
Date:
2022-12-21 20:04:03 UTC
List:
ruby-core #111366
Issue #13890 has been updated by shan (Shannon Skipper).
I'd love to have this feature. A `str.count(regexp)` is something I see fol=
k trying fairly often. A `str.count(regexp)` also avoids the intermediary A=
rray of `str.scan(regexp).size` or the back bending with `str.enum_for(:sca=
n, regexp).count`.
----------------------------------------
Feature #13890: Allow a regexp as an argument to 'count', to count more int=
eresting things than single characters
https://bugs.ruby-lang.org/issues/13890#change-100741
* Author: duerst (Martin D=FCrst)
* Status: Open
* Priority: Normal
----------------------------------------
Currently, String#count only accepts strings, and counts all the characters=
in the string.
However, I have repeatedly met the situation where I wanted to count more i=
nteresting things in strings.
These 'interesting things' can easily be expressed with regular expressions.
Here is a quick-and-dirty Ruby-level implementation:
````Ruby
class String
alias old_count count
def count (what)
case what
when String
old_count what
when Regexp
pos =3D -1
count =3D 0
count +=3D 1 while pos =3D index(what, pos+1)
count
end
end
end
````
Please note that the implementation counts overlapping occurrences; maybe t=
here is room for an option like `overlap: :no`.
--=20
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-c=
ore.ml.ruby-lang.org/