[#82706] [Ruby trunk Bug#13851] getting "can't modify string; temporarily locked" on non-frozen instances — cardoso_tiago@...
Issue #13851 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/07
[#82853] [Ruby trunk Bug#13916] Race condition when sending a signal to a new fork — russell.davis@...
Issue #13916 has been reported by russelldavis (Russell Davis).
3 messages
2017/09/19
[#82892] [Ruby trunk Bug#13921] buffered read_nonblock doesn't work as expected using SSLSocket — cardoso_tiago@...
Issue #13921 has been updated by chucke (Tiago Cardoso).
3 messages
2017/09/20
[ruby-core:82745] [Ruby trunk Feature#13890] Allow a regexp as an argument to 'count', to count more interesting things than single characters
From:
eregontp@...
Date:
2017-09-11 09:17:12 UTC
List:
ruby-core #82745
Issue #13890 has been updated by Eregon (Benoit Daloze).
Should it behave the same as str.scan(regexp).size ?
I think the default should be no overlap, and increment the position by the length of the match.
----------------------------------------
Feature #13890: Allow a regexp as an argument to 'count', to count more interesting things than single characters
https://bugs.ruby-lang.org/issues/13890#change-66601
* Author: duerst (Martin D端rst)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
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 interesting 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 = -1
count = 0
count += 1 while pos = index(what, pos+1)
count
end
end
end
````
Please note that the implementation counts overlapping occurrences; maybe there is room for an option like `overlap: :no`.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>