Gabriel Gilder
2010-01-20 18:23:20 UTC
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
***@gabrielgilder.com
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
***@gabrielgilder.com