Skip to content

Add reverse-string to ruby exercises #980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,16 @@
"topics": [
"arrays"
]
},
{
"slug": "reverse-string",
"uuid": "64c64613-9dd9-461e-90ba-90f84e17e197",
"core": false,
"unlocked_by": null,
"difficulty": 1,
"topics": [
"strings"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'generator/exercise_case'

class ReverseStringCase < Generator::ExerciseCase
def workload
[
"assert_equal #{expected.inspect}, ReverseString.reverse(#{value.inspect})"
]
end
end
3 changes: 3 additions & 0 deletions exercises/reverse-string/.meta/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hints

The Ruby library is pretty extensive! Look through Ruby's built-in `String` methods and see if you can find something that will help you out with this exercise.
5 changes: 5 additions & 0 deletions exercises/reverse-string/.meta/solutions/reverse_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ReverseString
def self.reverse(string)
string.reverse
end
end
42 changes: 42 additions & 0 deletions exercises/reverse-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Reverse String

Reverse a string

For example:
input: "cool"
output: "looc"

# Hints

The Ruby library is pretty extensive! Look through Ruby's built-in `String` methods and see if you can find something that will help you out with this exercise.


* * * *

For installation and learning resources, refer to the
[Ruby resources page](http://exercism.io/languages/ruby/resources).

For running the tests provided, you will need the Minitest gem. Open a
terminal window and run the following command to install minitest:

gem install minitest

If you would like color output, you can `require 'minitest/pride'` in
the test file, or note the alternative instruction, below, for running
the test file.

Run the tests from the exercise directory using the following command:

ruby reverse_string_test.rb

To include color from the command line:

ruby -r minitest/pride reverse_string_test.rb


## Source

Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
35 changes: 35 additions & 0 deletions exercises/reverse-string/reverse_string_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'minitest/autorun'
require_relative 'reverse_string'

# Common test data version: 1.2.0 6c95c2e
class ReverseStringTest < Minitest::Test
def test_an_empty_string
# skip
assert_equal "", ReverseString.reverse("")
end

def test_a_word
skip
assert_equal "tobor", ReverseString.reverse("robot")
end

def test_a_capitalized_word
skip
assert_equal "nemaR", ReverseString.reverse("Ramen")
end

def test_a_sentence_with_punctuation
skip
assert_equal "!yrgnuh m'I", ReverseString.reverse("I'm hungry!")
end

def test_a_palindrome
skip
assert_equal "racecar", ReverseString.reverse("racecar")
end

def test_an_even_sized_word
skip
assert_equal "reward", ReverseString.reverse("drawer")
end
end