elixir-lang/elixir — pull request #1769 by drueck (2013-10-17 22:45:55+00:00)
Title: Add version of String.slice that accepts a Range

Adding `String.slice/2` that accepts a Range, similar to the equivalent method on String in Ruby, with the notable minor exception that this version will return `nil` in all cases of a negative range (eg. `-2..-4` or `5..2`) whereas I believe the Ruby version would return `""` if the start of the range was a valid offset. I implemented it this way for consistency with how `String.slice/3` works, which returns nil for negative offsets.

I am very new to Elixir, so I very much welcome feedback and will gladly make any necessary changes! I'm particularly uncertain if I wrote the `@spec` line correctly.

Thanks!