The problem is not just for partition, but also involves split and scan.
I think your regex /^=*/ is unnecessarily complex. Your point can be made by /\A/, which is simpler.
I tried with four regex patterns /\A/, /\A.*/, /\z/, /.*\z/, and compared methods split, partition, scan. The result of the first example in each group below matches the second and the third, and the fourth one matches the middle element. So far, so good.
IIRC this has to do with zero-length matches being ignored in certain conditions, in particular having to do with repeating/multiple matches.
if "foo".split(/\A/) was ["","foo"]
then "foo".split(//) would have to be ["","f","o","o"]
and "foo".split(/\G/) could result in infinite loop matching ["","","","","",..."foo"]
But I don't understand why partition doesn't behave like match.
Ah, probably because it behaves like split(rx,2)
Note that gsub has different behavior: "foo".gsub(/\G/,'_') #=> "_f_o_o_" "foo".gsub(//,'_') #=> "_f_o_o_"
We'd like to focus on String#partition in this ticket.
IMO, String#scan and #split are heavily used so they should not change just for consistency reason. Please create another ticket if you really need to discuss. And a patch suggestion is welcome.
These methods have been taken from Python, and seems same in Python.
I'm not sure what's the rationale of this behavior.
I couldn't confirm it.
% python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "abc".partition("")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: empty separator
>>>