DEV Community

loading...

Discussion on: Daily Challenge #1 - String Peeler

Collapse
kaspermeyer profile image
Kasper Meyer • Edited

Ruby solution

require "minitest/autorun"

class WordTrimmer
  def initialize word
    @word = word
  end

  def trim
    @word.length <= 2 ? @word : @word[1..-2]
  end
end

class WordTrimmerTest < MiniTest::Test
  def test_removing_first_and_last_letter
    assert_equal "aspe", WordTrimmer.new("kasper").trim
  end

  def test_ignoring_two_letter_word
    assert_equal "hi", WordTrimmer.new("hi").trim
  end

  def test_ignoring_one_letter_word
    assert_equal "I", WordTrimmer.new("I").trim
  end
end