Docs for String.split
Gabriel Gilder <[email protected]> Wed, 20 Jan 2010 10:23:20 -0800
| Newsgroups | gmane.comp.lang.ruby.documentation |
|---|---|
| Message-ID | <[email protected]> |
--0016e64c388a5576eb047d9caedc
Content-Type: text/plain; charset=ISO-8859-1
Hi there,
Just joined to point out a small oversight in the Ruby docs - I looked into
the process for contributing documentation changes but it was a little over
my head. :) So I figured someone here could probably take care of it really
quickly.
So, the docs for String.split cover splitting by regex, but they don't
mention that if you have a capturing subpattern (or several) in your regex,
that gets included in the returned array.
For example:
"1, 2.34,56, 7".split(%r{(,\s*)}) #=> ["1", ", ", "2.34", ",", "56", ", ",
"7"]
"word :separator: word".split(/(:(\w+):)/) #=> ["word ", ":separator:",
"separator", " word"]
I've tested this in Ruby 1.8.7, but I imagine it works the same way in Ruby
1.9 as well, so both versions of the docs should probably be updated.
Thanks, please let me know if you have any questions!
-Gabriel
--------------------------------
Gabriel Gilder
Graphic Design & Web Programming
http://gabrielgilder.com
[email protected]
--0016e64c388a5576eb047d9caedc
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi there,<br>Just joined to point out a small oversight in the Ruby docs - =
I looked into the process for contributing documentation changes but it was=
a little over my head. :) So I figured someone here could probably take ca=
re of it really quickly.<br>
<br>So, the docs for String.split cover splitting by regex, but they don=
9;t mention that if you have a capturing subpattern (or several) in your re=
gex, that gets included in the returned array.<br><br>For example:<br><br>
"1, 2.34,56, 7".split(%r{(,\s*)}) #=3D> ["1", "=
, ", "2.34", ",", "56", ", ", =
"7"]<br>"word :separator: word".split(/(:(\w+):)/) #=3D=
> ["word ", ":separator:", "separator", &q=
uot; word"]<br>
<br>I've tested this in Ruby 1.8.7, but I imagine it works the same way=
in Ruby 1.9 as well, so both versions of the docs should probably be updat=
ed.<br><br>Thanks, please let me know if you have any questions!<br><br>
-Gabriel<br><br><br>
--------------------------------<br>
Gabriel Gilder<br>
Graphic Design & Web Programming<br>
<a href=3D"http://gabrielgilder.com">http://gabrielgilder.com</a><br>
<a href=3D"mailto:[email protected]">[email protected]</a><=
br>
<br>
--0016e64c388a5576eb047d9caedc--