[#84280] [Ruby trunk Bug#14181] hangs or deadlocks from waitpid, threads, and trapping SIGCHLD — nobu@...
Issue #14181 has been updated by nobu (Nobuyoshi Nakada).
3 messages
2017/12/15
[#84398] [Ruby trunk Bug#14220] WEBrick changes - failures on MSWIN, MinGW — Greg.mpls@...
Issue #14220 has been reported by MSP-Greg (Greg L).
3 messages
2017/12/22
[#84472] Re: [ruby-dev:50394] [Ruby trunk Bug#14240] warn four special variables: $; $, $/ $\ — Eric Wong <normalperson@...>
Shouldn't English posts be on ruby-core instead of ruby-dev?
3 messages
2017/12/26
[ruby-core:84559] [Ruby trunk Feature#13890] Allow a regexp as an argument to 'count', to count more interesting things than single characters
From:
duerst@...
Date:
2017-12-30 04:37:34 UTC
List:
ruby-core #84559
Issue #13890 has been updated by duerst (Martin D端rst).
Python allows to count strings, as follows:
`str.count(sub[, start[, end]])`
Return the number of non-overlapping occurrences of `substring` `sub` in the range `[start, end]`. Optional arguments `start` and `end` are interpreted as in slice notation.
----------------------------------------
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-69097
* 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>