Skip to content

Instantly share code, notes, and snippets.

@mikhailov
Created September 26, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikhailov/7c5c89601fa5c92122ce to your computer and use it in GitHub Desktop.
Save mikhailov/7c5c89601fa5c92122ce to your computer and use it in GitHub Desktop.
ReverseSentence
class ReverseSentence
def initialize(string)
@array, @array_reversed = string.split(" "), []
end
def process
@array_reversed << @array.pop while @array.any?
@array_reversed.join(" ")
end
end
require 'minitest/autorun'
class ReverseSentenceTest < Minitest::Unit::TestCase
def test_process
assert_equal "dogs likes bob", ReverseSentence.new("bob likes dogs").process
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment